Permalink
Browse files

Fixes #114 - In non-strict mode, accept non-breaking space as whitesp…

…ace.
  • Loading branch information...
1 parent 53e316a commit b0593f3ebb5cf83ad17a7f58876f61f1cea1a4bc @darronschall darronschall committed Aug 3, 2009
View
13 src/com/adobe/serialization/json/JSONTokenizer.as
@@ -618,7 +618,18 @@ package com.adobe.serialization.json {
*/
private function isWhiteSpace( ch:String ):Boolean
{
- return ( ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' );
+ // Check for the whitespace defined in the spec
+ if ( ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r' )
+ {
+ return true;
+ }
+ // If we're not in strict mode, we also accept non-breaking space
+ else if ( !strict && ch.charCodeAt( 0 ) == 160 )
+ {
+ return true;
+ }
+
+ return false;
}
/**
View
12 tests/src/com/adobe/serialization/json/JSONTest.as
@@ -350,6 +350,7 @@ package com.adobe.serialization.json
public function testDecodeWhiteSpace():void
{
var n:Number;
+ var nbsp:String = String.fromCharCode( 160 ); // non-breaking space
n = JSON.decode( " 1 " );
assertEquals( 1, n );
@@ -366,6 +367,17 @@ package com.adobe.serialization.json
// Verify combined before/after spacing
n = JSON.decode( "\t \n\n\r \r\n\t 100 \r\n\t\r\r\r\n \n" ) as Number
assertEquals( 100, n );
+
+ // In non-strict mode, we should also accept non breaking space
+ n = JSON.decode( "\t \n"
+ + nbsp
+ + "\n\r \r\n\t 100 \r\n\t\r\r\r\n"
+ + nbsp
+ + " \n", false ) as Number
+ assertEquals( 100, n );
+
+ // In strict mode, we do NOT accept non breaking space, so expect a parse error
+ expectParseError( "\t \n" + nbsp + "\n\r \r\n\t 100 \r\n\t\r\r\r\n" + nbsp + " \n" );
}
public function testDecodeWithCharactersLeftInInputString():void

0 comments on commit b0593f3

Please sign in to comment.