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

Closed
darronschall opened this Issue Jul 28, 2010 · 1 comment

Comments

Projects
None yet
1 participant
Contributor

darronschall commented Jul 28, 2010

Originally filed by danjwilson on 2009-08-23T12:51:56

What steps will reproduce the problem?

  1. Pass string ending in unicode escape sequence to JSON decoder

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.

Contributor

darronschall commented Jul 28, 2010

Updated by darron.schall on 2009-08-24T13:20:40

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 ticket set status to Fixed (we converted to closed)

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment