[Mono-bugs] [Bug 552340] New: JsonReader fails to parse json strings with \ in them

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Nov 3 18:34:21 EST 2009


http://bugzilla.novell.com/show_bug.cgi?id=552340


           Summary: JsonReader fails to parse json strings with \ in them
    Classification: Mono
           Product: Mono: Class Libraries
           Version: unspecified
          Platform: Other
        OS/Version: Mac OS X 10.6
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: System
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: john at moshakis.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_1; en-us)
AppleWebKit/531.9 (KHTML, like Gecko) Version/4.0.3 Safari/531.9

For a json string value to contain / values a \ must be placed. For example a
url

http:\/\/www.localhost.com

If a pass such a string into JsonReader from system.json

    public class Application
    {
        static void Main (string[] args)
        {
              var someJson =
"{\"source\":\"http:\\/\\/farm3.static.flickr.com\"}";

              using (var text = new StringReader(someJson))
            {

                var jsonReader = new JsonReader(text);

                var something = jsonReader.Read();

                var jObject = something as JsonObject;

                foreach(KeyValuePair<string,JsonValue> pair in jObject)
                {
                    switch(pair.Key)
                    {
                        case "source":
                        {
                            Console.WriteLine(pair.Value.ToString());
                            break;
                        }
                    }
                }

            }

then "http:4747farm3.static.flickr.com" is written to the console



Reproducible: Always

Steps to Reproduce:
1. Open the supplied monotouch project in MonoDevelop for OSX
2. Compile the application and run it in the simulator
3.
Actual Results:  
http:4747farm3.static.flickr.com is written to the console

Expected Results:  
http://farm3.static.flickr.com should be written to the console

Note: Attached is a monotouch project created in MonoDevelop for OSX

I pulled the source from source control and I think the problem is in the
ReadStringLiteral function in JsonReader  

This is the relevant piece of code

ReadChar ();
vb.Length = 0;
while (true) {
int c = ReadChar ();
if (c < 0)
throw JsonError ("JSON string is not closed");
if (c == '"')
return vb.ToString ();
else if (c != '\\') {
vb.Append ((char) c);
continue;
}

// escaped expression
c = ReadChar ();
if (c < 0)
throw JsonError ("Invalid JSON string literal; incomplete escape sequence");
switch (c) {
case '"':
case '\\':
case '/':

vb.append(c);



if I change the last line to

vb.Append ((char)c);


It fixes my issue

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list