diff --git a/src/com/adobe/serialization/json/JSONTokenizer.as b/src/com/adobe/serialization/json/JSONTokenizer.as index 46d2fd4..8ec2c96 100644 --- a/src/com/adobe/serialization/json/JSONTokenizer.as +++ b/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; } /** diff --git a/tests/src/com/adobe/serialization/json/JSONTest.as b/tests/src/com/adobe/serialization/json/JSONTest.as index 4e64e89..43b8e15 100644 --- a/tests/src/com/adobe/serialization/json/JSONTest.as +++ b/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