Mohsin26 / as3corelib

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

Error in JSONTokenizer's unescapeString() when string ends in unicode escape sequence #118

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Pass string ending in unicode escape sequence to JSON decoder
2.
3.

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

Unescaped string. Instead you get a JSON parse error: "Unexpected end of input. 
 Expecting 4 
hex digits after \u."

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

Bug introduced in revision 95

Please provide any additional information below.

The bug is in the check on line 340:

if ( nextSubstringStartPosition + 4 >= len )

which should be:

if ( nextSubstringStartPosition + 4 > len )

Example:

"\u1234" has len=6, nextSubstringStartPosition is the character after the "\u", 
in position 2, 
therefore (nextSubstringStartPosition + 4 >= len) evaluates to true and 
therefore throws a parse 
error.

Original issue reported on code.google.com by danjwilson on 23 Aug 2009 at 12:51

GoogleCodeExporter commented 9 years ago
Fixed in r97, thanks.  I actually had a test for this, but the test was 
incorrect (didn't escape the "\" before the u, 
which meant it the escape sequence wasn't actually an escape sequence by the 
time it was decoded... doh!).  

Fixing the test highlighted the problem, and your patch worked great to make 
the test pass.

Original comment by darron.schall on 24 Aug 2009 at 1:20