Skip to content

Commit f179a18

Browse files
committed
Fixed comment after value in object value signaled by Frederic Surleau.
1 parent 8868147 commit f179a18

4 files changed

Lines changed: 26 additions & 4 deletions

File tree

src/lib_json/json_reader.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,15 @@ Reader::readArray( Token &tokenStart )
557557
return recoverFromError( tokenArrayEnd );
558558

559559
Token token;
560-
if ( !readToken( token )
561-
|| ( token.type_ != tokenArraySeparator &&
562-
token.type_ != tokenArrayEnd ) )
560+
// Accept Comment after last item in the array.
561+
ok = readToken( token );
562+
while ( token.type_ == tokenComment && ok )
563+
{
564+
ok = readToken( token );
565+
}
566+
bool badTokenType = ( token.type_ == tokenArraySeparator &&
567+
token.type_ == tokenArrayEnd );
568+
if ( !ok || badTokenType )
563569
{
564570
return addErrorAndRecover( "Missing ',' or ']' in array declaration",
565571
token,

test/runjsontests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os.path
44
from glob import glob
55

6-
RUN_JSONCHECKER = True
6+
RUN_JSONCHECKER = False
77

88
def compareOutputs( expected, actual, message ):
99
expected = expected.strip().replace('\r','').split('\n')

test/test_comment_01.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.={}
2+
.test=[]
3+
.test[0]={}
4+
.test[0].a="aaa"
5+
.test[1]={}
6+
.test[1].b="bbb"
7+
.test[2]={}
8+
.test[2].c="ccc"

test/test_comment_01.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"test":
3+
[
4+
{ "a" : "aaa" }, // Comment for a
5+
{ "b" : "bbb" }, // Comment for b
6+
{ "c" : "ccc" } // Comment for c
7+
]
8+
}

0 commit comments

Comments
 (0)