diff --git a/modules/libcom/src/yajl/yajl_lex.c b/modules/libcom/src/yajl/yajl_lex.c index f780a3b0a..e59ce5488 100644 --- a/modules/libcom/src/yajl/yajl_lex.c +++ b/modules/libcom/src/yajl/yajl_lex.c @@ -153,7 +153,7 @@ static const char charLookupTable[256] = /*10*/ IJC , IJC , IJC , IJC , IJC , IJC , IJC , IJC , /*18*/ IJC , IJC , IJC , IJC , IJC , IJC , IJC , IJC , -/*20*/ 0 , 0 , NFP|VEC|IJC, 0 , VIC , 0 , 0 , 0 , +/*20*/ 0 , 0 , NFP|VEC, 0 , VIC , 0 , 0 , NFP|VEC, /*28*/ 0 , 0 , 0 , 0 , 0 , 0 , 0 , VEC , /*30*/ VHC|VIC, VHC|VIC, VHC|VIC, VHC|VIC, VHC|VIC, VHC|VIC, VHC|VIC, VHC|VIC, /*38*/ VHC|VIC, VHC|VIC, 0 , 0 , 0 , 0 , 0 , 0 , @@ -165,7 +165,7 @@ static const char charLookupTable[256] = /*60*/ 0 , VHC|VIC, VEC|VHC|VIC, VHC|VIC, VHC|VIC, VHC|VIC, VEC|VHC|VIC, VIC, /*68*/ VIC , VIC , VIC , VIC , VIC , VIC , VEC|VIC, VIC , -/*70*/ VIC , VIC , VEC , VIC , VEC|VIC, VIC , VIC , VIC , +/*70*/ VIC , VIC , VEC|VIC, VIC , VEC|VIC, VIC , VIC , VIC , /*78*/ VIC , VIC , VIC , 0 , 0 , 0 , 0 , 0 , NUC , NUC , NUC , NUC , NUC , NUC , NUC , NUC , @@ -277,7 +277,7 @@ yajl_string_scan(const unsigned char * buf, size_t len, int utf8check) static yajl_tok yajl_lex_string(yajl_lexer lexer, const unsigned char * jsonText, - size_t jsonTextLen, size_t * offset) + size_t jsonTextLen, size_t * offset, const char quote) { yajl_tok tok = yajl_tok_error; int hasEscapes = 0; @@ -312,7 +312,7 @@ yajl_lex_string(yajl_lexer lexer, const unsigned char * jsonText, curChar = readChar(lexer, jsonText, offset); /* quote terminates */ - if (curChar == '"') { + if (curChar == quote) { tok = yajl_tok_string; break; } @@ -406,7 +406,7 @@ yajl_lex_string(yajl_lexer lexer, const unsigned char * jsonText, static yajl_tok yajl_lex_identifier(yajl_lexer lexer, const unsigned char * jsonText, - size_t jsonTextLen, size_t * offset) + size_t jsonTextLen, size_t * offset) { unsigned char c; @@ -692,9 +692,11 @@ yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText, } goto lexed; } + case '\'': + if (!lexer->allowJson5) goto invalid; + /* Fall through... */ case '"': { - tok = yajl_lex_string(lexer, (const unsigned char *) jsonText, - jsonTextLen, offset); + tok = yajl_lex_string(lexer, jsonText, jsonTextLen, offset, c); goto lexed; } case '+': case '.': @@ -705,8 +707,7 @@ yajl_lex_lex(yajl_lexer lexer, const unsigned char * jsonText, case '5': case '6': case '7': case '8': case '9': { /* integer parsing wants to start from the beginning */ unreadChar(lexer, offset); - tok = yajl_lex_number(lexer, (const unsigned char *) jsonText, - jsonTextLen, offset); + tok = yajl_lex_number(lexer, jsonText, jsonTextLen, offset); goto lexed; } case '/': @@ -817,8 +818,11 @@ yajl_tok yajl_lex_key(yajl_lexer lexer, const unsigned char * jsonText, case '}': tok = yajl_tok_right_brace; goto lexed; + case '\'': + if (!lexer->allowJson5) goto invalid; + /* Fall through... */ case '"': { - tok = yajl_lex_string(lexer, jsonText, jsonTextLen, offset); + tok = yajl_lex_string(lexer, jsonText, jsonTextLen, offset, c); goto lexed; } case '/': @@ -853,6 +857,7 @@ yajl_tok yajl_lex_key(yajl_lexer lexer, const unsigned char * jsonText, tok = yajl_lex_identifier(lexer, jsonText, jsonTextLen, offset); } else { + invalid: lexer->error = yajl_lex_invalid_char; tok = yajl_tok_error; } diff --git a/modules/libcom/test/yajlTestCases.pm b/modules/libcom/test/yajlTestCases.pm index f2e7a8f93..7d2aff130 100644 --- a/modules/libcom/test/yajlTestCases.pm +++ b/modules/libcom/test/yajlTestCases.pm @@ -197,6 +197,54 @@ sub cases { "memory leaks:\t0" ] }, + { + name => "spec_example", + opts => [ + -5 + ], + input => [ + "{", + " // comments", + " unquoted: 'and you can quote me on that',", + " singleQuotes: 'I can use \"double quotes\" here',", + " lineBreaks: \"Look, Mom! \\", + "No \\\\n's!\",", + " hexadecimal: 0xdecaf,", + " leadingDecimalPoint: .8675309, andTrailing: 8675309.,", + " positiveSign: +1,", + " trailingComma: 'in objects', andIn: ['arrays',],", + " \"backwardsCompatible\": \"with JSON\",", + "}", + "" + ], + gives => [ + "map open '{'", + "key: 'unquoted'", + "string: 'and you can quote me on that'", + "key: 'singleQuotes'", + "string: 'I can use \"double quotes\" here'", + "key: 'lineBreaks'", + "string: 'Look, Mom! No \\n's!'", + "key: 'hexadecimal'", + "integer: 912559", + "key: 'leadingDecimalPoint'", + "double: 0.867531", + "key: 'andTrailing'", + "double: 8.67531e+06", + "key: 'positiveSign'", + "integer: 1", + "key: 'trailingComma'", + "string: 'in objects'", + "key: 'andIn'", + "array open '['", + "string: 'arrays'", + "array close ']'", + "key: 'backwardsCompatible'", + "string: 'with JSON'", + "map close '}'", + "memory leaks:\t0" + ] + }, { name => "strings", opts => [ @@ -204,7 +252,7 @@ sub cases { ], input => [ "[", - " \"Hello\\!\",", + " 'Hello\\!',", " \"\\\"Evenin\\',\\\" said the barman.\",", " // The following string has 3 different escaped line-endings,", " // LF, CR, and CR+LF, which all disappear from the final string.", @@ -212,7 +260,7 @@ sub cases { "hi \\\rthere \\\r", "y'all!\",", " \"\\b\\f\\n\\r\\t\\v\\\\\",", - " \"\\A\\C\\/\\D\\C\",", + " '\\A\\C\\/\\D\\C',", "]", "" ],