← Back to index
|
Original Bugzilla link
Bug 5366 – std.json parseJSON incorrectly parses unicode entities
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-12-23T10:03:00Z
Last change time
2011-01-11T18:40:51Z
Assigned to
nobody
Creator
ibuclaw
Comments
Comment #0
by ibuclaw — 2010-12-23T10:03:20Z
import std.json; import std.stdio; void main() { auto res = parseJSON(`"\u00F6"`); writefln("%s",res.str); // this should write "รถ" } Patch: --- d~/phobos/std/json.d +++ d/phobos/std/json.d @@ -156,7 +156,7 @@ foreach_reverse(i; 0 .. 4) { auto hex = toupper(getChar()); if(!isxdigit(hex)) error("Expecting hex character"); - val += (isdigit(hex) ? hex - '0' : hex - 'A') << (4 * i); + val += (isdigit(hex) ? hex - '0' : hex - '7') << (4 * i); } char[4] buf = void; str.put(toUTF8(buf, val)); Or (somewhat easier to under): --- d~/phobos2/std/json.d +++ d/phobos2/std/json.d @@ -156,7 +156,7 @@ foreach_reverse(i; 0 .. 4) { auto hex = toupper(getChar()); if(!isxdigit(hex)) error("Expecting hex character"); - val += (isdigit(hex) ? hex - '0' : hex - 'A') << (4 * i); + val += (isdigit(hex) ? hex - '0' : hex - 'A' + 10) << (4 * i); } char[4] buf = void; str.put(toUTF8(buf, val)); Regards
Comment #1
by ibuclaw — 2010-12-23T10:19:27Z
Unittest for testsuite: auto res = parseJSON(`"\u003C"`); assert(res.str == "\<"); res = parseJSON(`"\u003E"`); assert(res.str == "\>"); res = parseJSON(`"\u0391"`); assert(res.str == "\Α"); res = parseJSON(`"\u0392"`); assert(res.str == "\Β"); res = parseJSON(`"\u0393"`); assert(res.str == "\Γ"); res = parseJSON(`"\u2660"`); assert(res.str == "\♠"); res = parseJSON(`"\u2666"`); assert(res.str == "\♦"); Regards
Comment #2
by andrei — 2011-01-11T18:30:26Z
Iain, feel free to commit the fix yourself. Thanks!
Comment #3
by ibuclaw — 2011-01-11T18:39:19Z
Done and done.
http://dsource.org/projects/phobos/changeset/2317