kcjoon / as3corelib

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

Bug: JSONDecoder does not accept string ending in \u-escape sequence #134

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1a. var s:String = "\"\\u0040 \"";
1b. var s:String = "\"\\u0040\"";
1c. var s:String = "\"\\u004\"";
2. new JSONDecoder(s,false).getValue()

What is the expected output?
1a. "@ "
1b. "@"
1c. JSONParseError: Unexpected end of input.  Expecting 4 hex digits after \u.

What do you see instead?
1a. "@ " 
1b. JSONParseError: Unexpected end of input.  Expecting 4 hex digits after \u.
1c. JSONParseError: Unexpected end of input.  Expecting 4 hex digits after \u.

There error is the ">=" in line 339 of JSONTokenizer in current head:
http://code.google.com/p/as3corelib/source/browse/trunk/src/com/adobe/serializat
ion/json/JSONTokenizer.as#339

Change it to ">" and the expected results occur instead of the unexpected
error-containing results.

Original issue reported on code.google.com by morten.b...@gmail.com on 6 Jan 2010 at 10:22

GoogleCodeExporter commented 8 years ago
Would you be willing to submit a patch that contains the unit test to 
demonstrate the behavior, as well as the 
correction to the line of code you indicated about?

The new unit test should show that scenario 1b is currently failing, and then 
after making the change to the 
tokenizer the test (and all other pre-existing tests) should pass.

Original comment by darron.schall on 6 Jan 2010 at 2:42

GoogleCodeExporter commented 8 years ago
You actually already have a test for it:

http://code.google.com/p/as3corelib/source/browse/trunk/tests/src/com/adobe/seri
alization/json/JSONTest.as#115

This test should fail currently. I do not have Flex Builder nor FlexUnit, so I 
cannot
verify with the proper setup. But if I write:

JSON.decode( "\"\\u0061\"" )

It throws a runtime-error at me, so that test should definitely fail in any 
setup.

Could you please execute this test in your local setup? Maybe there is a 
problem with
the test-case not catching the error properly, and thus it seems like the whole
test-case works as it never asserts some false.

But in fact the function testDecodeStringWithInvalidUnicodeEscape throws an 
error.

Original comment by morten.b...@gmail.com on 11 Jan 2010 at 3:52