fyhack / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

Error during parsing hex codes. #108

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Try to parse string value with hex codes.

{
"title" : "The Dun \x26 Bradstreet Corporation",
"id" : "10242"
}

we get:

Caused by: com.google.gson.ParseException: Encountered "\"" at line 2,
column 20.
Was expecting one of:
    <DIGITS> ...
    "null" ...
    "NaN" ...
    "Infinity" ...
    <BOOLEAN> ...
    <SINGLE_QUOTE_LITERAL> ...
    <DOUBLE_QUOTE_LITERAL> ...
    "{" ...
    "[" ...
    "-" ...

What is the expected output? What do you see instead?

There must not be any errors!

What version of the product are you using? On what operating system?

1.3.b

Please provide any additional information below.

Original issue reported on code.google.com by alexande...@gmail.com on 24 Mar 2009 at 8:38

GoogleCodeExporter commented 9 years ago
Hex escapes are not a part of the JSON specification - or JSON RFC4627.
ParseException is the correct behavior when provided with invalid JSON.

The correct escape in your example is \u0026 instead of \x26.

Note: I am not a developer on this project, or with google.

Original comment by nuutti.k...@gmail.com on 26 Mar 2009 at 10:57

GoogleCodeExporter commented 9 years ago
As Nuutti points out, this is an invalid bug. You need to use the unicode 
escape 
sequence.

Original comment by inder123 on 27 Mar 2009 at 7:29