ref: 45c62b0fcc778c6e3f5e5ec684dcbd8437a4a9be
parent: 3fe66354265ae2a78c71df02808acf427a47c5c2
author: Tor Andersson <tor.andersson@artifex.com>
date: Tue Oct 28 08:21:04 EDT 2014
Fix JSON parsing problems: * false/true/null keywords * empty arrays and dictionaries * single quoted strings (are not allowed)
--- a/jslex.c
+++ b/jslex.c
@@ -742,12 +742,23 @@
case '{': NEXT(); return '{';
case '}': NEXT(); return '}';
- case '\'':
case '"':
return lexstring(J);
case '.':
return lexnumber(J);
+
+ case 'f':
+ NEXT(); EXPECT('a'); EXPECT('l'); EXPECT('s'); EXPECT('e');
+ return TK_FALSE;
+
+ case 'n':
+ NEXT(); EXPECT('u'); EXPECT('l'); EXPECT('l');
+ return TK_NULL;
+
+ case 't':
+ NEXT(); EXPECT('r'); EXPECT('u'); EXPECT('e');
+ return TK_TRUE;
case 0:
return 0; /* EOF */
--- a/json.c
+++ b/json.c
@@ -45,7 +45,7 @@
case '{':
js_newobject(J);
jsonnext(J);
- if (J->lookahead == '}')
+ if (jsonaccept(J, '}'))
return;
do {
if (J->lookahead != TK_STRING)
@@ -63,7 +63,7 @@
js_newarray(J);
jsonnext(J);
i = 0;
- if (J->lookahead == ']')
+ if (jsonaccept(J, ']'))
return;
do {
jsonvalue(J);