Skip to content

Commit 9a034ec

Browse files
Geod24WebFreak001
authored andcommitted
Support escaped forward slashes in YAML parser
Integrate fix for issue dlang-community/D-YAML#302 .
1 parent 11a8ac8 commit 9a034ec

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

source/dub/dub.d

+4-4
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,7 @@ unittest {
18481848
import configy.Read;
18491849

18501850
const str1 = `{
1851-
"registryUrls": [ "http://foo.bar" ],
1851+
"registryUrls": [ "http://foo.bar\/optional\/escape" ],
18521852
"customCachePaths": [ "foo/bar", "foo/foo" ],
18531853
18541854
"skipRegistry": "all",
@@ -1878,7 +1878,7 @@ unittest {
18781878
}`;
18791879

18801880
auto c1 = parseConfigString!UserConfiguration(str1, "/dev/null");
1881-
assert(c1.registryUrls == [ "http://foo.bar" ]);
1881+
assert(c1.registryUrls == [ "http://foo.bar/optional/escape" ]);
18821882
assert(c1.customCachePaths == [ NativePath("foo/bar"), NativePath("foo/foo") ]);
18831883
assert(c1.skipRegistry == SkipPackageSuppliers.all);
18841884
assert(c1.defaultCompiler == "dmd");
@@ -1901,7 +1901,7 @@ unittest {
19011901

19021902
auto m1 = c2.merge(c1);
19031903
// c1 takes priority, so its registryUrls is first
1904-
assert(m1.registryUrls == [ "http://foo.bar", "http://bar.foo" ]);
1904+
assert(m1.registryUrls == [ "http://foo.bar/optional/escape", "http://bar.foo" ]);
19051905
// Same with CCP
19061906
assert(m1.customCachePaths == [
19071907
NativePath("foo/bar"), NativePath("foo/foo"),
@@ -1916,7 +1916,7 @@ unittest {
19161916
assert(m1.defaultEnvironments == c1.defaultEnvironments);
19171917

19181918
auto m2 = c1.merge(c2);
1919-
assert(m2.registryUrls == [ "http://bar.foo", "http://foo.bar" ]);
1919+
assert(m2.registryUrls == [ "http://bar.foo", "http://foo.bar/optional/escape" ]);
19201920
assert(m2.customCachePaths == [
19211921
NativePath("bar/foo"), NativePath("bar/bar"),
19221922
NativePath("foo/bar"), NativePath("foo/foo"),

source/dyaml/escapes.d

+15-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ package:
1111

1212
import std.meta : AliasSeq;
1313
alias escapes = AliasSeq!('0', 'a', 'b', 't', '\t', 'n', 'v', 'f', 'r', 'e', ' ',
14-
'\"', '\\', 'N', '_', 'L', 'P');
14+
'/', '\"', '\\', 'N', '_', 'L', 'P');
1515

1616
/// YAML hex codes specifying the length of the hex number.
1717
alias escapeHexCodeList = AliasSeq!('x', 'u', 'U');
@@ -32,6 +32,7 @@ dchar fromEscape(dchar escape) @safe pure nothrow @nogc
3232
case 'r': return '\x0D';
3333
case 'e': return '\x1B';
3434
case ' ': return '\x20';
35+
case '/': return '/';
3536
case '\"': return '\"';
3637
case '\\': return '\\';
3738
case 'N': return '\x85'; //'\u0085';
@@ -90,3 +91,16 @@ uint escapeHexLength(dchar hexCode) @safe pure nothrow @nogc
9091
}
9192
}
9293

94+
// Issue #302: Support optional escaping of forward slashes in string
95+
// for JSON compatibility
96+
@safe unittest
97+
{
98+
import dyaml.loader : Loader;
99+
100+
const str = `{
101+
"forward/slashes": "can\/be\/optionally\/escaped"
102+
}`;
103+
104+
auto node = Loader.fromString(str).load();
105+
assert(node["forward/slashes"] == "can/be/optionally/escaped");
106+
}

0 commit comments

Comments
 (0)