From 9c98f2277b2972ddee93c97bb5273e86d6045195 Mon Sep 17 00:00:00 2001 From: Baptiste Lepilleur Date: Sun, 1 May 2011 15:40:47 +0000 Subject: [PATCH] Fixed bug #3139677: JSON [1 2 3] was incorrectly parsed as [1, 3]. Error is now correctly detected. Modified runjsontests.py to allow test that expect failure in jsoncpp test suite. --- NEWS.txt | 5 +++++ src/lib_json/json_reader.cpp | 4 ++-- test/data/fail_test_array_01.json | 1 + test/runjsontests.py | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 test/data/fail_test_array_01.json diff --git a/NEWS.txt b/NEWS.txt index 9924691..ce1d014 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -68,6 +68,11 @@ - Added test to ensure that the escape sequence "\/" is corrected handled by the parser. +* Bug fixes + + - Bug #3139677: JSON [1 2 3] was incorrectly parsed as [1, 3]. Error is now correctly + detected. + * License - See file LICENSE for details. Basically JsonCpp is now licensed under diff --git a/src/lib_json/json_reader.cpp b/src/lib_json/json_reader.cpp index 60dc4c9..508eb16 100644 --- a/src/lib_json/json_reader.cpp +++ b/src/lib_json/json_reader.cpp @@ -533,8 +533,8 @@ Reader::readArray( Token &tokenStart ) { ok = readToken( token ); } - bool badTokenType = ( token.type_ == tokenArraySeparator && - token.type_ == tokenArrayEnd ); + bool badTokenType = ( token.type_ != tokenArraySeparator && + token.type_ != tokenArrayEnd ); if ( !ok || badTokenType ) { return addErrorAndRecover( "Missing ',' or ']' in array declaration", diff --git a/test/data/fail_test_array_01.json b/test/data/fail_test_array_01.json new file mode 100644 index 0000000..900fcc2 --- /dev/null +++ b/test/data/fail_test_array_01.json @@ -0,0 +1 @@ +[ 1 2 3] diff --git a/test/runjsontests.py b/test/runjsontests.py index 800337d..ffe8bd5 100644 --- a/test/runjsontests.py +++ b/test/runjsontests.py @@ -49,7 +49,8 @@ def runAllTests( jsontest_executable_path, input_dir = None, failed_tests = [] valgrind_path = use_valgrind and VALGRIND_CMD or '' for input_path in tests + test_jsonchecker: - is_json_checker_test = input_path in test_jsonchecker + expect_failure = os.path.basename( input_path ).startswith( 'fail' ) + is_json_checker_test = (input_path in test_jsonchecker) or expect_failure print 'TESTING:', input_path, options = is_json_checker_test and '--json-checker' or '' pipe = os.popen( "%s%s %s %s" % ( @@ -58,7 +59,6 @@ def runAllTests( jsontest_executable_path, input_dir = None, process_output = pipe.read() status = pipe.close() if is_json_checker_test: - expect_failure = os.path.basename( input_path ).startswith( 'fail' ) if expect_failure: if status is None: print 'FAILED'