JSONTokenizer doesn't recognize all instances of Non-breaking spaces #110

Closed
darronschall opened this Issue Jul 28, 2010 · 2 comments

Comments

Projects
None yet
1 participant
Contributor

darronschall commented Jul 28, 2010

Originally filed by omarrr on 2009-07-29T22:19:00

Pasting into a JSON file a long string generated from the Output panel in
the Flash IDE will generate whitespaces that are not recognized by the
JSONTokenizer class. Trying to parse it will generate an exception:

[Fault] exception, information=JSONParseError: Unexpected character ' '
(code=160) encountered
Fault, parseError() at JSONTokenizer.as:544
xxx throw new JSONParseError( message, loc, jsonString );

(Note: The extra information with the charcode was added to the original code)

To fix this the following function in JSONTokenizer:

private function isWhiteSpace( ch:String ):Boolean
{
return ( ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' );
}

can be replaced with:

private function isWhiteSpace( ch:String ):Boolean
{
return ( ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' ||
ch.charCodeAt(0)==160 );
}

Contributor

darronschall commented Jul 28, 2010

Updated by darron.schall on 2009-08-02T20:10:32

I don't think this is a bug in the JSON parser in strict mode. According to the RFC, whitespace is defined as:

ws = *(
%x20 / ; Space
%x09 / ; Horizontal tab
%x0A / ; Line feed or New line
%x0D ; Carriage return
)

Character 160 is a non-breaking space, and not valid JSON whitespace.

However, if the parser is used in non-strict mode then I can deal with this better by including the non-
breaking space as whitespace.

Added label strict
Original ticket set status to Accepted (we converted to open)

Contributor

darronschall commented Jul 28, 2010

Updated by darron.schall on 2009-08-03T00:18:47

Fixed in r93

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