www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5366] New: std.json parseJSON incorrectly parses unicode entities

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5366

           Summary: std.json parseJSON incorrectly parses unicode entities
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: ibuclaw ubuntu.com


--- Comment #0 from Iain Buclaw <ibuclaw ubuntu.com> 2010-12-23 10:03:20 PST ---
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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 23 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5366



--- Comment #1 from Iain Buclaw <ibuclaw ubuntu.com> 2010-12-23 10:19:27 PST ---
Unittest for testsuite:


auto res = parseJSON(`"\u003C"`);
assert(res.str == "\&lt;");
res = parseJSON(`"\u003E"`);
assert(res.str == "\&gt;");
res = parseJSON(`"\u0391"`);
assert(res.str == "\&Alpha;");
res = parseJSON(`"\u0392"`);
assert(res.str == "\&Beta;");
res = parseJSON(`"\u0393"`);
assert(res.str == "\&Gamma;");
res = parseJSON(`"\u2660"`);
assert(res.str == "\&spades;");
res = parseJSON(`"\u2666"`);
assert(res.str == "\&diams;");

Regards

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 23 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5366


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei metalanguage.com


--- Comment #2 from Andrei Alexandrescu <andrei metalanguage.com> 2011-01-11
18:30:26 PST ---
Iain, feel free to commit the fix yourself. Thanks!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 11 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5366



--- Comment #3 from Iain Buclaw <ibuclaw ubuntu.com> 2011-01-11 18:39:19 PST ---
Done and done.

http://dsource.org/projects/phobos/changeset/2317

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 11 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5366


Iain Buclaw <ibuclaw ubuntu.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 11 2011