Skip to content

Commit

Permalink
Fix issue 15884 Encode wstring/wchar[]/dstring/dchar[] as JSON string
Browse files Browse the repository at this point in the history
  • Loading branch information
lionello committed Apr 14, 2016
1 parent 4547f8c commit 1f1ed03
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions std/json.d
Expand Up @@ -346,10 +346,14 @@ struct JSONValue
type_tag = JSON_TYPE.STRING;
store.str = arg;
}
else static if(is(T : char[]))
else static if(isSomeString!T) // issue 15884
{
type_tag = JSON_TYPE.STRING;
store.str = arg.idup;
// FIXME: std.array.array(Range) is not deduced as 'pure'
() @trusted {
import std.utf : byUTF;
store.str = cast(immutable)(arg.byUTF!char.array);
}();
}
else static if(is(T : bool))
{
Expand Down Expand Up @@ -1700,7 +1704,16 @@ pure nothrow @safe @nogc unittest

pure nothrow @safe unittest // issue 15884
{
char[] str = "a".dup;
JSONValue testVal = str;
assert(testVal.type == JSON_TYPE.STRING);
import std.typecons;
void Test(C)() {
C[] a = ['x'];
JSONValue testVal = a;
assert(testVal.type == JSON_TYPE.STRING);
testVal = a.idup;
assert(testVal.type == JSON_TYPE.STRING);
}
Test!char();
Test!wchar();
Test!dchar();
}

0 comments on commit 1f1ed03

Please sign in to comment.