From 30dc22790c4b8bc64e7f336aeb779974cbb9e8a9 Mon Sep 17 00:00:00 2001 From: Simulant Date: Fri, 22 Mar 2024 12:02:09 +0100 Subject: [PATCH 01/11] extend syntax error information --- src/main/java/org/json/JSONTokener.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/json/JSONTokener.java b/src/main/java/org/json/JSONTokener.java index 0bc6dfb68..5f724b13d 100644 --- a/src/main/java/org/json/JSONTokener.java +++ b/src/main/java/org/json/JSONTokener.java @@ -299,7 +299,8 @@ public String nextString(char quote) throws JSONException { case 0: case '\n': case '\r': - throw this.syntaxError("Unterminated string"); + throw this.syntaxError("Unterminated string. " + + "Character with int code " + (int) c + " is not allowed within a quoted string."); case '\\': c = this.next(); switch (c) { @@ -322,7 +323,7 @@ public String nextString(char quote) throws JSONException { try { sb.append((char)Integer.parseInt(this.next(4), 16)); } catch (NumberFormatException e) { - throw this.syntaxError("Illegal escape.", e); + throw this.syntaxError("Illegal escape. \\u must be followed by a 4 digit number.", e); } break; case '"': @@ -332,7 +333,7 @@ public String nextString(char quote) throws JSONException { sb.append(c); break; default: - throw this.syntaxError("Illegal escape."); + throw this.syntaxError("Illegal escape. Escape sequence \\" + c + " is not valid."); } break; default: @@ -521,7 +522,7 @@ public JSONException syntaxError(String message, Throwable causedBy) { */ @Override public String toString() { - return " at " + this.index + " [character " + this.character + " line " + + return " at index: " + this.index + " [character number " + this.character + " in line " + this.line + "]"; } From 6c160b7d1a12132531a149dd260118f3f993d321 Mon Sep 17 00:00:00 2001 From: Simulant Date: Fri, 22 Mar 2024 12:08:06 +0100 Subject: [PATCH 02/11] leave JSONTokener.toString unchanged --- src/main/java/org/json/JSONTokener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/json/JSONTokener.java b/src/main/java/org/json/JSONTokener.java index 5f724b13d..51110e121 100644 --- a/src/main/java/org/json/JSONTokener.java +++ b/src/main/java/org/json/JSONTokener.java @@ -522,7 +522,7 @@ public JSONException syntaxError(String message, Throwable causedBy) { */ @Override public String toString() { - return " at index: " + this.index + " [character number " + this.character + " in line " + + return " at " + this.index + " [character " + this.character + " line " + this.line + "]"; } From f1c9d0787b3aab056574cb1a9f528b6a5b85c67e Mon Sep 17 00:00:00 2001 From: Simulant Date: Sat, 23 Mar 2024 21:49:58 +0100 Subject: [PATCH 03/11] add test cases for extended syntax error exception messages --- src/main/java/org/json/JSONTokener.java | 6 ++- .../java/org/json/junit/JSONObjectTest.java | 54 +++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/json/JSONTokener.java b/src/main/java/org/json/JSONTokener.java index 51110e121..b8808bb4f 100644 --- a/src/main/java/org/json/JSONTokener.java +++ b/src/main/java/org/json/JSONTokener.java @@ -320,10 +320,12 @@ public String nextString(char quote) throws JSONException { sb.append('\r'); break; case 'u': + String next = this.next(4); try { - sb.append((char)Integer.parseInt(this.next(4), 16)); + sb.append((char)Integer.parseInt(next, 16)); } catch (NumberFormatException e) { - throw this.syntaxError("Illegal escape. \\u must be followed by a 4 digit number.", e); + throw this.syntaxError("Illegal escape. " + + "\\u must be followed by a 4 digit hexadecimal number. \\" + next + " is not valid.", e); } break; case '"': diff --git a/src/test/java/org/json/junit/JSONObjectTest.java b/src/test/java/org/json/junit/JSONObjectTest.java index fac8c5388..a8b25eb73 100644 --- a/src/test/java/org/json/junit/JSONObjectTest.java +++ b/src/test/java/org/json/junit/JSONObjectTest.java @@ -2193,6 +2193,60 @@ public void jsonObjectParseControlCharacters(){ } } + @Test + public void jsonObjectParseControlCharacterEOFAssertExceptionMessage(){ + char c = '\0'; + final String source = "{\"key\":\"" + c + "\"}"; + try { + JSONObject jo = new JSONObject(source); + fail("JSONException should be thrown"); + } catch (JSONException ex) { + assertEquals("Unterminated string. " + "Character with int code 0" + + " is not allowed within a quoted string. at 8 [character 9 line 1]", ex.getMessage()); + } + } + + @Test + public void jsonObjectParseControlCharacterNewLineAssertExceptionMessage(){ + char[] chars = {'\n', '\r'}; + for( char c : chars) { + final String source = "{\"key\":\"" + c + "\"}"; + try { + JSONObject jo = new JSONObject(source); + fail("JSONException should be thrown"); + } catch (JSONException ex) { + assertEquals("Unterminated string. " + "Character with int code " + (int) c + + " is not allowed within a quoted string. at 9 [character 0 line 2]", ex.getMessage()); + } + } + } + + @Test + public void jsonObjectParseUTF8EncodingAssertExceptionMessage(){ + String c = "\\u123x"; + final String source = "{\"key\":\"" + c + "\"}"; + try { + JSONObject jo = new JSONObject(source); + fail("JSONException should be thrown"); + } catch (JSONException ex) { + assertEquals("Illegal escape. \\u must be followed by a 4 digit hexadecimal number. " + + "\\123x is not valid. at 14 [character 15 line 1]", ex.getMessage()); + } + } + + @Test + public void jsonObjectParseIllegalEscapeAssertExceptionMessage(){ + String c = "\\x"; + final String source = "{\"key\":\"" + c + "\"}"; + try { + JSONObject jo = new JSONObject(source); + fail("JSONException should be thrown"); + } catch (JSONException ex) { + assertEquals("Illegal escape. Escape sequence " + c + " is not valid." + + " at 10 [character 11 line 1]", ex.getMessage()); + } + } + /** * Explore how JSONObject handles parsing errors. */ From d69d5e284b3ee797f3950d80eb9dfc571a944284 Mon Sep 17 00:00:00 2001 From: Simulant Date: Sat, 23 Mar 2024 22:02:54 +0100 Subject: [PATCH 04/11] explain position information numbers in syntax exception --- src/main/java/org/json/JSONTokener.java | 4 +- src/test/java/org/json/junit/CDLTest.java | 10 +-- .../java/org/json/junit/CookieListTest.java | 2 +- src/test/java/org/json/junit/CookieTest.java | 2 +- .../java/org/json/junit/JSONArrayTest.java | 8 +-- src/test/java/org/json/junit/JSONMLTest.java | 22 +++---- .../java/org/json/junit/JSONObjectTest.java | 42 ++++++------ .../java/org/json/junit/JSONTokenerTest.java | 66 +++++++++---------- .../org/json/junit/XMLConfigurationTest.java | 12 ++-- src/test/java/org/json/junit/XMLTest.java | 12 ++-- 10 files changed, 90 insertions(+), 90 deletions(-) diff --git a/src/main/java/org/json/JSONTokener.java b/src/main/java/org/json/JSONTokener.java index b8808bb4f..8b7a34a33 100644 --- a/src/main/java/org/json/JSONTokener.java +++ b/src/main/java/org/json/JSONTokener.java @@ -520,11 +520,11 @@ public JSONException syntaxError(String message, Throwable causedBy) { /** * Make a printable string of this JSONTokener. * - * @return " at {index} [character {character} line {line}]" + * @return " at index {index} [character number {character} in line {line}]" */ @Override public String toString() { - return " at " + this.index + " [character " + this.character + " line " + + return " at index " + this.index + " [character number " + this.character + " in line " + this.line + "]"; } diff --git a/src/test/java/org/json/junit/CDLTest.java b/src/test/java/org/json/junit/CDLTest.java index cc3da2983..3584e9e09 100644 --- a/src/test/java/org/json/junit/CDLTest.java +++ b/src/test/java/org/json/junit/CDLTest.java @@ -66,7 +66,7 @@ public void unbalancedQuoteInName() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Missing close quote '\"'. at 12 [character 0 line 2]", + "Missing close quote '\"'. at index 12 [character number 0 in line 2]", e.getMessage()); } } @@ -83,7 +83,7 @@ public void unbalancedQuoteInValue() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Missing close quote '\"'. at 22 [character 11 line 2]", + "Missing close quote '\"'. at index 22 [character number 11 in line 2]", e.getMessage()); } @@ -101,7 +101,7 @@ public void nullInName() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Bad character 'o' (111). at 2 [character 3 line 1]", + "Bad character 'o' (111). at index 2 [character number 3 in line 1]", e.getMessage()); } @@ -119,7 +119,7 @@ public void unbalancedEscapedQuote(){ fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Missing close quote '\"'. at 26 [character 15 line 2]", + "Missing close quote '\"'. at index 26 [character number 15 in line 2]", e.getMessage()); } @@ -170,7 +170,7 @@ public void badEscapedQuote(){ } catch (JSONException e) { //System.out.println("Message" + e.getMessage()); assertEquals("Expecting an exception message", - "Bad character 'V' (86). at 20 [character 9 line 2]", + "Bad character 'V' (86). at index 20 [character number 9 in line 2]", e.getMessage()); } diff --git a/src/test/java/org/json/junit/CookieListTest.java b/src/test/java/org/json/junit/CookieListTest.java index 0af96401b..908090b47 100644 --- a/src/test/java/org/json/junit/CookieListTest.java +++ b/src/test/java/org/json/junit/CookieListTest.java @@ -57,7 +57,7 @@ public void malFormedCookieListException() { * Not sure of the missing char, but full string compare fails */ assertEquals("Expecting an exception message", - "Expected '=' and instead saw '' at 25 [character 26 line 1]", + "Expected '=' and instead saw '' at index 25 [character number 26 in line 1]", e.getMessage()); } } diff --git a/src/test/java/org/json/junit/CookieTest.java b/src/test/java/org/json/junit/CookieTest.java index edd8a7eeb..766952557 100644 --- a/src/test/java/org/json/junit/CookieTest.java +++ b/src/test/java/org/json/junit/CookieTest.java @@ -48,7 +48,7 @@ public void malFormedNameValueException() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Expected '=' and instead saw '' at 25 [character 26 line 1]", + "Expected '=' and instead saw '' at index 25 [character number 26 in line 1]", e.getMessage()); } } diff --git a/src/test/java/org/json/junit/JSONArrayTest.java b/src/test/java/org/json/junit/JSONArrayTest.java index fcaa8cea0..bb0b435b4 100644 --- a/src/test/java/org/json/junit/JSONArrayTest.java +++ b/src/test/java/org/json/junit/JSONArrayTest.java @@ -127,7 +127,7 @@ public void emptyStr() { assertNull("Should throw an exception", new JSONArray(str)); } catch (JSONException e) { assertEquals("Expected an exception message", - "A JSONArray text must start with '[' at 0 [character 1 line 1]", + "A JSONArray text must start with '[' at index 0 [character number 1 in line 1]", e.getMessage()); } } @@ -142,7 +142,7 @@ public void unclosedArray() { assertNull("Should throw an exception", new JSONArray("[")); } catch (JSONException e) { assertEquals("Expected an exception message", - "Expected a ',' or ']' at 1 [character 2 line 1]", + "Expected a ',' or ']' at index 1 [character number 2 in line 1]", e.getMessage()); } } @@ -157,7 +157,7 @@ public void unclosedArray2() { assertNull("Should throw an exception", new JSONArray("[\"test\"")); } catch (JSONException e) { assertEquals("Expected an exception message", - "Expected a ',' or ']' at 7 [character 8 line 1]", + "Expected a ',' or ']' at index 7 [character number 8 in line 1]", e.getMessage()); } } @@ -172,7 +172,7 @@ public void unclosedArray3() { assertNull("Should throw an exception", new JSONArray("[\"test\",")); } catch (JSONException e) { assertEquals("Expected an exception message", - "Expected a ',' or ']' at 8 [character 9 line 1]", + "Expected a ',' or ']' at index 8 [character number 9 in line 1]", e.getMessage()); } } diff --git a/src/test/java/org/json/junit/JSONMLTest.java b/src/test/java/org/json/junit/JSONMLTest.java index 154af645f..80fa3cd5c 100644 --- a/src/test/java/org/json/junit/JSONMLTest.java +++ b/src/test/java/org/json/junit/JSONMLTest.java @@ -49,7 +49,7 @@ public void emptyXMLException() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Bad XML at 0 [character 1 line 1]", + "Bad XML at index 0 [character number 1 in line 1]", e.getMessage()); } } @@ -102,7 +102,7 @@ public void nonXMLException() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Bad XML at 23 [character 24 line 1]", + "Bad XML at index 23 [character number 24 in line 1]", e.getMessage()); } } @@ -205,7 +205,7 @@ public void invalidSlashInTagException() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Misshaped tag at 176 [character 14 line 4]", + "Misshaped tag at index 176 [character number 14 in line 4]", e.getMessage()); } } @@ -230,7 +230,7 @@ public void invalidBangInTagException() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Misshaped meta tag at 215 [character 12 line 7]", + "Misshaped meta tag at index 215 [character number 12 in line 7]", e.getMessage()); } } @@ -260,7 +260,7 @@ public void invalidBangNoCloseInTagException() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Misshaped meta tag at 214 [character 12 line 7]", + "Misshaped meta tag at index 214 [character number 12 in line 7]", e.getMessage()); } } @@ -290,7 +290,7 @@ public void noCloseStartTagException() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Misplaced '<' at 194 [character 5 line 6]", + "Misplaced '<' at index 194 [character number 5 in line 6]", e.getMessage()); } } @@ -350,7 +350,7 @@ public void noCloseEndBraceException() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Misplaced '<' at 206 [character 1 line 7]", + "Misplaced '<' at index 206 [character number 1 in line 7]", e.getMessage()); } } @@ -380,7 +380,7 @@ public void invalidCDATABangInTagException() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Expected 'CDATA[' at 204 [character 11 line 5]", + "Expected 'CDATA[' at index 204 [character number 11 in line 5]", e.getMessage()); } } @@ -682,7 +682,7 @@ public void commentsInXML() { "
\n"+ "\n"+ "Joe Tester\n"+ - "\n"+ "Baker street 5\n"+ "
\n"+ @@ -815,7 +815,7 @@ public void testIssue484InfinteLoop1() { fail("Exception expected for invalid JSON."); } catch (JSONException ex) { assertEquals("Exception string did not match: ", - "Unterminated string at 271 [character 272 line 1]", + "Unterminated string at index 271 [character number 272 in line 1]", ex.getMessage()); } } @@ -829,7 +829,7 @@ public void testIssue484InfinteLoop2() { fail("Exception expected for invalid JSON."); } catch (JSONException ex) { assertEquals("Exception string did not match: ", - "Unterminated string at 242 [character 238 line 2]", + "Unterminated string at index 242 [character number 238 in line 2]", ex.getMessage()); } } diff --git a/src/test/java/org/json/junit/JSONObjectTest.java b/src/test/java/org/json/junit/JSONObjectTest.java index a8b25eb73..b4c85b32a 100644 --- a/src/test/java/org/json/junit/JSONObjectTest.java +++ b/src/test/java/org/json/junit/JSONObjectTest.java @@ -2202,7 +2202,7 @@ public void jsonObjectParseControlCharacterEOFAssertExceptionMessage(){ fail("JSONException should be thrown"); } catch (JSONException ex) { assertEquals("Unterminated string. " + "Character with int code 0" + - " is not allowed within a quoted string. at 8 [character 9 line 1]", ex.getMessage()); + " is not allowed within a quoted string. at index 8 [character number 9 in line 1]", ex.getMessage()); } } @@ -2216,7 +2216,7 @@ public void jsonObjectParseControlCharacterNewLineAssertExceptionMessage(){ fail("JSONException should be thrown"); } catch (JSONException ex) { assertEquals("Unterminated string. " + "Character with int code " + (int) c + - " is not allowed within a quoted string. at 9 [character 0 line 2]", ex.getMessage()); + " is not allowed within a quoted string. at index 9 [character number 0 in line 2]", ex.getMessage()); } } } @@ -2230,7 +2230,7 @@ public void jsonObjectParseUTF8EncodingAssertExceptionMessage(){ fail("JSONException should be thrown"); } catch (JSONException ex) { assertEquals("Illegal escape. \\u must be followed by a 4 digit hexadecimal number. " + - "\\123x is not valid. at 14 [character 15 line 1]", ex.getMessage()); + "\\123x is not valid. at index 14 [character number 15 in line 1]", ex.getMessage()); } } @@ -2243,7 +2243,7 @@ public void jsonObjectParseIllegalEscapeAssertExceptionMessage(){ fail("JSONException should be thrown"); } catch (JSONException ex) { assertEquals("Illegal escape. Escape sequence " + c + " is not valid." + - " at 10 [character 11 line 1]", ex.getMessage()); + " at index 10 [character number 11 in line 1]", ex.getMessage()); } } @@ -2259,7 +2259,7 @@ public void jsonObjectParsingErrors() { assertNull("Expected an exception",new JSONObject(str)); } catch (JSONException e) { assertEquals("Expecting an exception message", - "A JSONObject text must begin with '{' at 1 [character 2 line 1]", + "A JSONObject text must begin with '{' at index 1 [character number 2 in line 1]", e.getMessage()); } try { @@ -2268,7 +2268,7 @@ public void jsonObjectParsingErrors() { assertNull("Expected an exception",new JSONObject(str)); } catch (JSONException e) { assertEquals("Expecting an exception message", - "A JSONObject text must end with '}' at 1 [character 2 line 1]", + "A JSONObject text must end with '}' at index 1 [character number 2 in line 1]", e.getMessage()); } try { @@ -2277,7 +2277,7 @@ public void jsonObjectParsingErrors() { assertNull("Expected an exception",new JSONObject(str)); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Expected a ':' after a key at 10 [character 11 line 1]", + "Expected a ':' after a key at index 10 [character number 11 in line 1]", e.getMessage()); } try { @@ -2286,7 +2286,7 @@ public void jsonObjectParsingErrors() { assertNull("Expected an exception",new JSONObject(str)); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Expected a ',' or '}' at 15 [character 16 line 1]", + "Expected a ',' or '}' at index 15 [character number 16 in line 1]", e.getMessage()); } try { @@ -2295,7 +2295,7 @@ public void jsonObjectParsingErrors() { assertNull("Expected an exception",new JSONObject(str)); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Missing value at 1 [character 2 line 1]", + "Missing value at index 1 [character number 2 in line 1]", e.getMessage()); } try { @@ -2304,7 +2304,7 @@ public void jsonObjectParsingErrors() { assertNull("Expected an exception",new JSONObject(str)); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Missing value at 9 [character 10 line 1]", + "Missing value at index 9 [character number 10 in line 1]", e.getMessage()); } try { @@ -2313,7 +2313,7 @@ public void jsonObjectParsingErrors() { assertNull("Expected an exception",new JSONObject(str)); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Expected a ':' after a key at 5 [character 6 line 1]", + "Expected a ':' after a key at index 5 [character number 6 in line 1]", e.getMessage()); } try { @@ -2322,7 +2322,7 @@ public void jsonObjectParsingErrors() { assertNull("Expected an exception",new JSONObject(str)); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Expected a ':' after a key at 5 [character 6 line 1]", + "Expected a ':' after a key at index 5 [character number 6 in line 1]", e.getMessage()); } try { @@ -2331,7 +2331,7 @@ public void jsonObjectParsingErrors() { assertNull("Expected an exception",new JSONObject(str)); } catch (JSONException e) { assertEquals("Expecting an exception message", - "A JSONObject text must end with '}' at 15 [character 16 line 1]", + "A JSONObject text must end with '}' at index 15 [character number 16 in line 1]", e.getMessage()); } try { @@ -2412,7 +2412,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr03\" at 90 [character 13 line 5]", + "Duplicate key \"attr03\" at index 90 [character number 13 in line 5]", e.getMessage()); } try { @@ -2431,7 +2431,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr03\" at 90 [character 13 line 5]", + "Duplicate key \"attr03\" at index 90 [character number 13 in line 5]", e.getMessage()); } try { @@ -2452,7 +2452,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr03\" at 90 [character 13 line 5]", + "Duplicate key \"attr03\" at index 90 [character number 13 in line 5]", e.getMessage()); } try { @@ -2472,7 +2472,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", + "Duplicate key \"attr04-03\" at index 215 [character number 20 in line 9]", e.getMessage()); } try { @@ -2496,7 +2496,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", + "Duplicate key \"attr04-03\" at index 215 [character number 20 in line 9]", e.getMessage()); } try { @@ -2522,7 +2522,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", + "Duplicate key \"attr04-03\" at index 215 [character number 20 in line 9]", e.getMessage()); } try { @@ -2541,7 +2541,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr01\" at 124 [character 17 line 8]", + "Duplicate key \"attr01\" at index 124 [character number 17 in line 8]", e.getMessage()); } try { @@ -2566,7 +2566,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr02-01\" at 269 [character 24 line 13]", + "Duplicate key \"attr02-01\" at index 269 [character number 24 in line 13]", e.getMessage()); } } diff --git a/src/test/java/org/json/junit/JSONTokenerTest.java b/src/test/java/org/json/junit/JSONTokenerTest.java index 59ca6d8f6..4738b8ad7 100644 --- a/src/test/java/org/json/junit/JSONTokenerTest.java +++ b/src/test/java/org/json/junit/JSONTokenerTest.java @@ -233,7 +233,7 @@ public void testSkipToSuccessWithStringReader() throws IOException { /** * Verify that next and back are working properly and tracking the correct positions - * with different new line combinations. + * with different new in line combinations. */ @Test public void testNextBackComboWithNewLines() { @@ -241,74 +241,74 @@ public void testNextBackComboWithNewLines() { // ^ ^ ^ ^ // index positions 0 8 16 36 final JSONTokener tokener = new JSONTokener(testString); - assertEquals(" at 0 [character 1 line 1]", tokener.toString()); + assertEquals(" at index 0 [character number 1 in line 1]", tokener.toString()); assertEquals('t',tokener.next()); - assertEquals(" at 1 [character 2 line 1]", tokener.toString()); + assertEquals(" at index 1 [character number 2 in line 1]", tokener.toString()); tokener.skipTo('\n'); - assertEquals("skipTo() improperly modifying indexes"," at 7 [character 8 line 1]", tokener.toString()); + assertEquals("skipTo() improperly modifying indexes"," at index 7 [character number 8 in line 1]", tokener.toString()); assertEquals('\n',tokener.next()); - assertEquals(" at 8 [character 0 line 2]", tokener.toString()); + assertEquals(" at index 8 [character number 0 in line 2]", tokener.toString()); assertEquals('A',tokener.next()); - assertEquals(" at 9 [character 1 line 2]", tokener.toString()); + assertEquals(" at index 9 [character number 1 in line 2]", tokener.toString()); tokener.back(); - assertEquals(" at 8 [character 0 line 2]", tokener.toString()); + assertEquals(" at index 8 [character number 0 in line 2]", tokener.toString()); tokener.skipTo('\r'); - assertEquals("skipTo() improperly modifying indexes"," at 14 [character 6 line 2]", tokener.toString()); - // verify \r\n combo doesn't increment the line twice + assertEquals("skipTo() improperly modifying indexes"," at index 14 [character number 6 in line 2]", tokener.toString()); + // verify \r\n combo doesn't increment the in line twice assertEquals('\r', tokener.next()); - assertEquals(" at 15 [character 0 line 3]", tokener.toString()); + assertEquals(" at index 15 [character number 0 in line 3]", tokener.toString()); assertEquals('\n', tokener.next()); - assertEquals(" at 16 [character 0 line 3]", tokener.toString()); - // verify stepping back after reading the \n of an \r\n combo doesn't increment the line incorrectly + assertEquals(" at index 16 [character number 0 in line 3]", tokener.toString()); + // verify stepping back after reading the \n of an \r\n combo doesn't increment the in line incorrectly tokener.back(); - assertEquals(" at 15 [character 6 line 2]", tokener.toString()); + assertEquals(" at index 15 [character number 6 in line 2]", tokener.toString()); assertEquals('\n', tokener.next()); - assertEquals(" at 16 [character 0 line 3]", tokener.toString()); + assertEquals(" at index 16 [character number 0 in line 3]", tokener.toString()); assertEquals('W', tokener.next()); - assertEquals(" at 17 [character 1 line 3]", tokener.toString()); + assertEquals(" at index 17 [character number 1 in line 3]", tokener.toString()); assertEquals('i', tokener.next()); - assertEquals(" at 18 [character 2 line 3]", tokener.toString()); + assertEquals(" at index 18 [character number 2 in line 3]", tokener.toString()); tokener.skipTo('\r'); - assertEquals("skipTo() improperly modifying indexes"," at 35 [character 19 line 3]", tokener.toString()); + assertEquals("skipTo() improperly modifying indexes"," at index 35 [character number 19 in line 3]", tokener.toString()); assertEquals('\r', tokener.next()); - assertEquals(" at 36 [character 0 line 4]", tokener.toString()); + assertEquals(" at index 36 [character number 0 in line 4]", tokener.toString()); tokener.back(); - assertEquals(" at 35 [character 19 line 3]", tokener.toString()); + assertEquals(" at index 35 [character number 19 in line 3]", tokener.toString()); assertEquals('\r', tokener.next()); - assertEquals(" at 36 [character 0 line 4]", tokener.toString()); + assertEquals(" at index 36 [character number 0 in line 4]", tokener.toString()); assertEquals('N', tokener.next()); - assertEquals(" at 37 [character 1 line 4]", tokener.toString()); + assertEquals(" at index 37 [character number 1 in line 4]", tokener.toString()); // verify we get the same data just walking though, no calls to back final JSONTokener t2 = new JSONTokener(testString); for(int i=0; i<7; i++) { - assertTrue(t2.toString().startsWith(" at " + i + " ")); + assertTrue(t2.toString().startsWith(" at index " + i + " ")); assertEquals(testString.charAt(i), t2.next()); } - assertEquals(" at 7 [character 8 line 1]", t2.toString()); + assertEquals(" at index 7 [character number 8 in line 1]", t2.toString()); assertEquals(testString.charAt(7), t2.next()); - assertEquals(" at 8 [character 0 line 2]", t2.toString()); + assertEquals(" at index 8 [character number 0 in line 2]", t2.toString()); for(int i=8; i<14; i++) { - assertTrue(t2.toString().startsWith(" at " + i + " ")); + assertTrue(t2.toString().startsWith(" at index " + i + " ")); assertEquals(testString.charAt(i), t2.next()); } - assertEquals(" at 14 [character 6 line 2]", t2.toString()); + assertEquals(" at index 14 [character number 6 in line 2]", t2.toString()); assertEquals('\r', t2.next()); - assertEquals(" at 15 [character 0 line 3]", t2.toString()); + assertEquals(" at index 15 [character number 0 in line 3]", t2.toString()); assertEquals('\n', t2.next()); - assertEquals(" at 16 [character 0 line 3]", t2.toString()); + assertEquals(" at index 16 [character number 0 in line 3]", t2.toString()); assertEquals('W', t2.next()); - assertEquals(" at 17 [character 1 line 3]", t2.toString()); + assertEquals(" at index 17 [character number 1 in line 3]", t2.toString()); for(int i=17; i<37; i++) { - assertTrue(t2.toString().startsWith(" at " + i + " ")); + assertTrue(t2.toString().startsWith(" at index " + i + " ")); assertEquals(testString.charAt(i), t2.next()); } - assertEquals(" at 37 [character 1 line 4]", t2.toString()); + assertEquals(" at index 37 [character number 1 in line 4]", t2.toString()); for(int i=37; i\n"+ " comment ]]>\n"+ " Joe Tester\n"+ - " \n"+ " Baker street 5\n"+ " \n"+ diff --git a/src/test/java/org/json/junit/XMLTest.java b/src/test/java/org/json/junit/XMLTest.java index 3b26b22e2..6fabfb566 100644 --- a/src/test/java/org/json/junit/XMLTest.java +++ b/src/test/java/org/json/junit/XMLTest.java @@ -93,7 +93,7 @@ public void shouldHandleInvalidSlashInTag() { fail("Expecting a JSONException"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Misshaped tag at 176 [character 14 line 4]", + "Misshaped tag at index 176 [character number 14 in line 4]", e.getMessage()); } } @@ -118,7 +118,7 @@ public void shouldHandleInvalidBangInTag() { fail("Expecting a JSONException"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Misshaped meta tag at 214 [character 12 line 7]", + "Misshaped meta tag at index 214 [character number 12 in line 7]", e.getMessage()); } } @@ -143,7 +143,7 @@ public void shouldHandleInvalidBangNoCloseInTag() { fail("Expecting a JSONException"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Misshaped meta tag at 213 [character 12 line 7]", + "Misshaped meta tag at index 213 [character number 12 in line 7]", e.getMessage()); } } @@ -168,7 +168,7 @@ public void shouldHandleNoCloseStartTag() { fail("Expecting a JSONException"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Misplaced '<' at 193 [character 4 line 6]", + "Misplaced '<' at index 193 [character number 4 in line 6]", e.getMessage()); } } @@ -193,7 +193,7 @@ public void shouldHandleInvalidCDATABangInTag() { fail("Expecting a JSONException"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Expected 'CDATA[' at 204 [character 11 line 5]", + "Expected 'CDATA[' at index 204 [character number 11 in line 5]", e.getMessage()); } } @@ -350,7 +350,7 @@ public void shouldHandleCommentsInXML() { "
\n"+ " comment ]]>\n"+ " Joe Tester\n"+ - " \n"+ " Baker street 5\n"+ "
\n"+ From 4e39d8ccf2a99bc70a0354283e87df821a4050e8 Mon Sep 17 00:00:00 2001 From: Simulant87 Date: Sat, 23 Mar 2024 22:03:57 +0100 Subject: [PATCH 05/11] fix wrong comment update --- src/test/java/org/json/junit/JSONMLTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/json/junit/JSONMLTest.java b/src/test/java/org/json/junit/JSONMLTest.java index 80fa3cd5c..9fdfa57ad 100644 --- a/src/test/java/org/json/junit/JSONMLTest.java +++ b/src/test/java/org/json/junit/JSONMLTest.java @@ -682,7 +682,7 @@ public void commentsInXML() { "
\n"+ "\n"+ "Joe Tester\n"+ - "\n"+ "Baker street 5\n"+ "
\n"+ From ccb4a9b95f6e38834501b7c313c02839fac6474f Mon Sep 17 00:00:00 2001 From: Simulant87 Date: Sat, 23 Mar 2024 22:04:53 +0100 Subject: [PATCH 06/11] fix wrong comment update --- src/test/java/org/json/junit/JSONTokenerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/json/junit/JSONTokenerTest.java b/src/test/java/org/json/junit/JSONTokenerTest.java index 4738b8ad7..cbd8d72e8 100644 --- a/src/test/java/org/json/junit/JSONTokenerTest.java +++ b/src/test/java/org/json/junit/JSONTokenerTest.java @@ -233,7 +233,7 @@ public void testSkipToSuccessWithStringReader() throws IOException { /** * Verify that next and back are working properly and tracking the correct positions - * with different new in line combinations. + * with different new line combinations. */ @Test public void testNextBackComboWithNewLines() { From 78151beea2c03bcf186b65655b3cfd174b0723f3 Mon Sep 17 00:00:00 2001 From: Simulant87 Date: Sat, 23 Mar 2024 22:05:27 +0100 Subject: [PATCH 07/11] fix wrong comment update --- src/test/java/org/json/junit/JSONTokenerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/json/junit/JSONTokenerTest.java b/src/test/java/org/json/junit/JSONTokenerTest.java index cbd8d72e8..bed309791 100644 --- a/src/test/java/org/json/junit/JSONTokenerTest.java +++ b/src/test/java/org/json/junit/JSONTokenerTest.java @@ -259,7 +259,7 @@ public void testNextBackComboWithNewLines() { assertEquals(" at index 15 [character number 0 in line 3]", tokener.toString()); assertEquals('\n', tokener.next()); assertEquals(" at index 16 [character number 0 in line 3]", tokener.toString()); - // verify stepping back after reading the \n of an \r\n combo doesn't increment the in line incorrectly + // verify stepping back after reading the \n of an \r\n combo doesn't increment the line incorrectly tokener.back(); assertEquals(" at index 15 [character number 6 in line 2]", tokener.toString()); assertEquals('\n', tokener.next()); From 75a34a246ff77db80c82d487da0e803f0d91ed91 Mon Sep 17 00:00:00 2001 From: Simulant87 Date: Sat, 23 Mar 2024 22:05:51 +0100 Subject: [PATCH 08/11] fix wrong comment update --- src/test/java/org/json/junit/JSONTokenerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/json/junit/JSONTokenerTest.java b/src/test/java/org/json/junit/JSONTokenerTest.java index bed309791..19c5cdb72 100644 --- a/src/test/java/org/json/junit/JSONTokenerTest.java +++ b/src/test/java/org/json/junit/JSONTokenerTest.java @@ -254,7 +254,7 @@ public void testNextBackComboWithNewLines() { assertEquals(" at index 8 [character number 0 in line 2]", tokener.toString()); tokener.skipTo('\r'); assertEquals("skipTo() improperly modifying indexes"," at index 14 [character number 6 in line 2]", tokener.toString()); - // verify \r\n combo doesn't increment the in line twice + // verify \r\n combo doesn't increment the line twice assertEquals('\r', tokener.next()); assertEquals(" at index 15 [character number 0 in line 3]", tokener.toString()); assertEquals('\n', tokener.next()); From 7324cc0b26814534113d51ad5bfcdce5dd11ebe0 Mon Sep 17 00:00:00 2001 From: Simulant87 Date: Sat, 23 Mar 2024 22:06:20 +0100 Subject: [PATCH 09/11] fix wrong comment update --- src/test/java/org/json/junit/XMLConfigurationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/json/junit/XMLConfigurationTest.java b/src/test/java/org/json/junit/XMLConfigurationTest.java index 22e2be3a3..45a07a678 100755 --- a/src/test/java/org/json/junit/XMLConfigurationTest.java +++ b/src/test/java/org/json/junit/XMLConfigurationTest.java @@ -298,7 +298,7 @@ public void shouldHandleCommentsInXML() { "
\n"+ " comment ]]>\n"+ " Joe Tester\n"+ - " \n"+ " Baker street 5\n"+ "
\n"+ From 78cdb3d0d607425cdf9c5d73ecac4d897098ed4c Mon Sep 17 00:00:00 2001 From: Simulant87 Date: Sat, 23 Mar 2024 22:07:05 +0100 Subject: [PATCH 10/11] fix wrong comment update --- src/test/java/org/json/junit/XMLTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/json/junit/XMLTest.java b/src/test/java/org/json/junit/XMLTest.java index 6fabfb566..a565c24b9 100644 --- a/src/test/java/org/json/junit/XMLTest.java +++ b/src/test/java/org/json/junit/XMLTest.java @@ -350,7 +350,7 @@ public void shouldHandleCommentsInXML() { "
\n"+ " comment ]]>\n"+ " Joe Tester\n"+ - " \n"+ " Baker street 5\n"+ "
\n"+ From 0fcf3528485f3ff439f1b5aa8aa90663e37be220 Mon Sep 17 00:00:00 2001 From: Simulant Date: Wed, 27 Mar 2024 20:35:43 +0100 Subject: [PATCH 11/11] Revert "explain position information numbers in syntax exception" This reverts commit d69d5e284b3ee797f3950d80eb9dfc571a944284. --- src/main/java/org/json/JSONTokener.java | 4 +- src/test/java/org/json/junit/CDLTest.java | 10 ++-- .../java/org/json/junit/CookieListTest.java | 2 +- src/test/java/org/json/junit/CookieTest.java | 2 +- .../java/org/json/junit/JSONArrayTest.java | 8 +-- src/test/java/org/json/junit/JSONMLTest.java | 20 +++---- .../java/org/json/junit/JSONObjectTest.java | 42 ++++++------- .../java/org/json/junit/JSONTokenerTest.java | 60 +++++++++---------- .../org/json/junit/XMLConfigurationTest.java | 10 ++-- src/test/java/org/json/junit/XMLTest.java | 10 ++-- 10 files changed, 84 insertions(+), 84 deletions(-) diff --git a/src/main/java/org/json/JSONTokener.java b/src/main/java/org/json/JSONTokener.java index 8b7a34a33..b8808bb4f 100644 --- a/src/main/java/org/json/JSONTokener.java +++ b/src/main/java/org/json/JSONTokener.java @@ -520,11 +520,11 @@ public JSONException syntaxError(String message, Throwable causedBy) { /** * Make a printable string of this JSONTokener. * - * @return " at index {index} [character number {character} in line {line}]" + * @return " at {index} [character {character} line {line}]" */ @Override public String toString() { - return " at index " + this.index + " [character number " + this.character + " in line " + + return " at " + this.index + " [character " + this.character + " line " + this.line + "]"; } diff --git a/src/test/java/org/json/junit/CDLTest.java b/src/test/java/org/json/junit/CDLTest.java index 3584e9e09..cc3da2983 100644 --- a/src/test/java/org/json/junit/CDLTest.java +++ b/src/test/java/org/json/junit/CDLTest.java @@ -66,7 +66,7 @@ public void unbalancedQuoteInName() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Missing close quote '\"'. at index 12 [character number 0 in line 2]", + "Missing close quote '\"'. at 12 [character 0 line 2]", e.getMessage()); } } @@ -83,7 +83,7 @@ public void unbalancedQuoteInValue() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Missing close quote '\"'. at index 22 [character number 11 in line 2]", + "Missing close quote '\"'. at 22 [character 11 line 2]", e.getMessage()); } @@ -101,7 +101,7 @@ public void nullInName() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Bad character 'o' (111). at index 2 [character number 3 in line 1]", + "Bad character 'o' (111). at 2 [character 3 line 1]", e.getMessage()); } @@ -119,7 +119,7 @@ public void unbalancedEscapedQuote(){ fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Missing close quote '\"'. at index 26 [character number 15 in line 2]", + "Missing close quote '\"'. at 26 [character 15 line 2]", e.getMessage()); } @@ -170,7 +170,7 @@ public void badEscapedQuote(){ } catch (JSONException e) { //System.out.println("Message" + e.getMessage()); assertEquals("Expecting an exception message", - "Bad character 'V' (86). at index 20 [character number 9 in line 2]", + "Bad character 'V' (86). at 20 [character 9 line 2]", e.getMessage()); } diff --git a/src/test/java/org/json/junit/CookieListTest.java b/src/test/java/org/json/junit/CookieListTest.java index 908090b47..0af96401b 100644 --- a/src/test/java/org/json/junit/CookieListTest.java +++ b/src/test/java/org/json/junit/CookieListTest.java @@ -57,7 +57,7 @@ public void malFormedCookieListException() { * Not sure of the missing char, but full string compare fails */ assertEquals("Expecting an exception message", - "Expected '=' and instead saw '' at index 25 [character number 26 in line 1]", + "Expected '=' and instead saw '' at 25 [character 26 line 1]", e.getMessage()); } } diff --git a/src/test/java/org/json/junit/CookieTest.java b/src/test/java/org/json/junit/CookieTest.java index 766952557..edd8a7eeb 100644 --- a/src/test/java/org/json/junit/CookieTest.java +++ b/src/test/java/org/json/junit/CookieTest.java @@ -48,7 +48,7 @@ public void malFormedNameValueException() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Expected '=' and instead saw '' at index 25 [character number 26 in line 1]", + "Expected '=' and instead saw '' at 25 [character 26 line 1]", e.getMessage()); } } diff --git a/src/test/java/org/json/junit/JSONArrayTest.java b/src/test/java/org/json/junit/JSONArrayTest.java index bb0b435b4..fcaa8cea0 100644 --- a/src/test/java/org/json/junit/JSONArrayTest.java +++ b/src/test/java/org/json/junit/JSONArrayTest.java @@ -127,7 +127,7 @@ public void emptyStr() { assertNull("Should throw an exception", new JSONArray(str)); } catch (JSONException e) { assertEquals("Expected an exception message", - "A JSONArray text must start with '[' at index 0 [character number 1 in line 1]", + "A JSONArray text must start with '[' at 0 [character 1 line 1]", e.getMessage()); } } @@ -142,7 +142,7 @@ public void unclosedArray() { assertNull("Should throw an exception", new JSONArray("[")); } catch (JSONException e) { assertEquals("Expected an exception message", - "Expected a ',' or ']' at index 1 [character number 2 in line 1]", + "Expected a ',' or ']' at 1 [character 2 line 1]", e.getMessage()); } } @@ -157,7 +157,7 @@ public void unclosedArray2() { assertNull("Should throw an exception", new JSONArray("[\"test\"")); } catch (JSONException e) { assertEquals("Expected an exception message", - "Expected a ',' or ']' at index 7 [character number 8 in line 1]", + "Expected a ',' or ']' at 7 [character 8 line 1]", e.getMessage()); } } @@ -172,7 +172,7 @@ public void unclosedArray3() { assertNull("Should throw an exception", new JSONArray("[\"test\",")); } catch (JSONException e) { assertEquals("Expected an exception message", - "Expected a ',' or ']' at index 8 [character number 9 in line 1]", + "Expected a ',' or ']' at 8 [character 9 line 1]", e.getMessage()); } } diff --git a/src/test/java/org/json/junit/JSONMLTest.java b/src/test/java/org/json/junit/JSONMLTest.java index 9fdfa57ad..154af645f 100644 --- a/src/test/java/org/json/junit/JSONMLTest.java +++ b/src/test/java/org/json/junit/JSONMLTest.java @@ -49,7 +49,7 @@ public void emptyXMLException() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Bad XML at index 0 [character number 1 in line 1]", + "Bad XML at 0 [character 1 line 1]", e.getMessage()); } } @@ -102,7 +102,7 @@ public void nonXMLException() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Bad XML at index 23 [character number 24 in line 1]", + "Bad XML at 23 [character 24 line 1]", e.getMessage()); } } @@ -205,7 +205,7 @@ public void invalidSlashInTagException() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Misshaped tag at index 176 [character number 14 in line 4]", + "Misshaped tag at 176 [character 14 line 4]", e.getMessage()); } } @@ -230,7 +230,7 @@ public void invalidBangInTagException() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Misshaped meta tag at index 215 [character number 12 in line 7]", + "Misshaped meta tag at 215 [character 12 line 7]", e.getMessage()); } } @@ -260,7 +260,7 @@ public void invalidBangNoCloseInTagException() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Misshaped meta tag at index 214 [character number 12 in line 7]", + "Misshaped meta tag at 214 [character 12 line 7]", e.getMessage()); } } @@ -290,7 +290,7 @@ public void noCloseStartTagException() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Misplaced '<' at index 194 [character number 5 in line 6]", + "Misplaced '<' at 194 [character 5 line 6]", e.getMessage()); } } @@ -350,7 +350,7 @@ public void noCloseEndBraceException() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Misplaced '<' at index 206 [character number 1 in line 7]", + "Misplaced '<' at 206 [character 1 line 7]", e.getMessage()); } } @@ -380,7 +380,7 @@ public void invalidCDATABangInTagException() { fail("Expecting an exception"); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Expected 'CDATA[' at index 204 [character number 11 in line 5]", + "Expected 'CDATA[' at 204 [character 11 line 5]", e.getMessage()); } } @@ -815,7 +815,7 @@ public void testIssue484InfinteLoop1() { fail("Exception expected for invalid JSON."); } catch (JSONException ex) { assertEquals("Exception string did not match: ", - "Unterminated string at index 271 [character number 272 in line 1]", + "Unterminated string at 271 [character 272 line 1]", ex.getMessage()); } } @@ -829,7 +829,7 @@ public void testIssue484InfinteLoop2() { fail("Exception expected for invalid JSON."); } catch (JSONException ex) { assertEquals("Exception string did not match: ", - "Unterminated string at index 242 [character number 238 in line 2]", + "Unterminated string at 242 [character 238 line 2]", ex.getMessage()); } } diff --git a/src/test/java/org/json/junit/JSONObjectTest.java b/src/test/java/org/json/junit/JSONObjectTest.java index b4c85b32a..a8b25eb73 100644 --- a/src/test/java/org/json/junit/JSONObjectTest.java +++ b/src/test/java/org/json/junit/JSONObjectTest.java @@ -2202,7 +2202,7 @@ public void jsonObjectParseControlCharacterEOFAssertExceptionMessage(){ fail("JSONException should be thrown"); } catch (JSONException ex) { assertEquals("Unterminated string. " + "Character with int code 0" + - " is not allowed within a quoted string. at index 8 [character number 9 in line 1]", ex.getMessage()); + " is not allowed within a quoted string. at 8 [character 9 line 1]", ex.getMessage()); } } @@ -2216,7 +2216,7 @@ public void jsonObjectParseControlCharacterNewLineAssertExceptionMessage(){ fail("JSONException should be thrown"); } catch (JSONException ex) { assertEquals("Unterminated string. " + "Character with int code " + (int) c + - " is not allowed within a quoted string. at index 9 [character number 0 in line 2]", ex.getMessage()); + " is not allowed within a quoted string. at 9 [character 0 line 2]", ex.getMessage()); } } } @@ -2230,7 +2230,7 @@ public void jsonObjectParseUTF8EncodingAssertExceptionMessage(){ fail("JSONException should be thrown"); } catch (JSONException ex) { assertEquals("Illegal escape. \\u must be followed by a 4 digit hexadecimal number. " + - "\\123x is not valid. at index 14 [character number 15 in line 1]", ex.getMessage()); + "\\123x is not valid. at 14 [character 15 line 1]", ex.getMessage()); } } @@ -2243,7 +2243,7 @@ public void jsonObjectParseIllegalEscapeAssertExceptionMessage(){ fail("JSONException should be thrown"); } catch (JSONException ex) { assertEquals("Illegal escape. Escape sequence " + c + " is not valid." + - " at index 10 [character number 11 in line 1]", ex.getMessage()); + " at 10 [character 11 line 1]", ex.getMessage()); } } @@ -2259,7 +2259,7 @@ public void jsonObjectParsingErrors() { assertNull("Expected an exception",new JSONObject(str)); } catch (JSONException e) { assertEquals("Expecting an exception message", - "A JSONObject text must begin with '{' at index 1 [character number 2 in line 1]", + "A JSONObject text must begin with '{' at 1 [character 2 line 1]", e.getMessage()); } try { @@ -2268,7 +2268,7 @@ public void jsonObjectParsingErrors() { assertNull("Expected an exception",new JSONObject(str)); } catch (JSONException e) { assertEquals("Expecting an exception message", - "A JSONObject text must end with '}' at index 1 [character number 2 in line 1]", + "A JSONObject text must end with '}' at 1 [character 2 line 1]", e.getMessage()); } try { @@ -2277,7 +2277,7 @@ public void jsonObjectParsingErrors() { assertNull("Expected an exception",new JSONObject(str)); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Expected a ':' after a key at index 10 [character number 11 in line 1]", + "Expected a ':' after a key at 10 [character 11 line 1]", e.getMessage()); } try { @@ -2286,7 +2286,7 @@ public void jsonObjectParsingErrors() { assertNull("Expected an exception",new JSONObject(str)); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Expected a ',' or '}' at index 15 [character number 16 in line 1]", + "Expected a ',' or '}' at 15 [character 16 line 1]", e.getMessage()); } try { @@ -2295,7 +2295,7 @@ public void jsonObjectParsingErrors() { assertNull("Expected an exception",new JSONObject(str)); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Missing value at index 1 [character number 2 in line 1]", + "Missing value at 1 [character 2 line 1]", e.getMessage()); } try { @@ -2304,7 +2304,7 @@ public void jsonObjectParsingErrors() { assertNull("Expected an exception",new JSONObject(str)); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Missing value at index 9 [character number 10 in line 1]", + "Missing value at 9 [character 10 line 1]", e.getMessage()); } try { @@ -2313,7 +2313,7 @@ public void jsonObjectParsingErrors() { assertNull("Expected an exception",new JSONObject(str)); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Expected a ':' after a key at index 5 [character number 6 in line 1]", + "Expected a ':' after a key at 5 [character 6 line 1]", e.getMessage()); } try { @@ -2322,7 +2322,7 @@ public void jsonObjectParsingErrors() { assertNull("Expected an exception",new JSONObject(str)); } catch (JSONException e) { assertEquals("Expecting an exception message", - "Expected a ':' after a key at index 5 [character number 6 in line 1]", + "Expected a ':' after a key at 5 [character 6 line 1]", e.getMessage()); } try { @@ -2331,7 +2331,7 @@ public void jsonObjectParsingErrors() { assertNull("Expected an exception",new JSONObject(str)); } catch (JSONException e) { assertEquals("Expecting an exception message", - "A JSONObject text must end with '}' at index 15 [character number 16 in line 1]", + "A JSONObject text must end with '}' at 15 [character 16 line 1]", e.getMessage()); } try { @@ -2412,7 +2412,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr03\" at index 90 [character number 13 in line 5]", + "Duplicate key \"attr03\" at 90 [character 13 line 5]", e.getMessage()); } try { @@ -2431,7 +2431,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr03\" at index 90 [character number 13 in line 5]", + "Duplicate key \"attr03\" at 90 [character 13 line 5]", e.getMessage()); } try { @@ -2452,7 +2452,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr03\" at index 90 [character number 13 in line 5]", + "Duplicate key \"attr03\" at 90 [character 13 line 5]", e.getMessage()); } try { @@ -2472,7 +2472,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr04-03\" at index 215 [character number 20 in line 9]", + "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", e.getMessage()); } try { @@ -2496,7 +2496,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr04-03\" at index 215 [character number 20 in line 9]", + "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", e.getMessage()); } try { @@ -2522,7 +2522,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr04-03\" at index 215 [character number 20 in line 9]", + "Duplicate key \"attr04-03\" at 215 [character 20 line 9]", e.getMessage()); } try { @@ -2541,7 +2541,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr01\" at index 124 [character number 17 in line 8]", + "Duplicate key \"attr01\" at 124 [character 17 line 8]", e.getMessage()); } try { @@ -2566,7 +2566,7 @@ public void jsonObjectParsingErrors() { fail("Expected an exception"); } catch (JSONException e) { assertEquals("Expecting an expection message", - "Duplicate key \"attr02-01\" at index 269 [character number 24 in line 13]", + "Duplicate key \"attr02-01\" at 269 [character 24 line 13]", e.getMessage()); } } diff --git a/src/test/java/org/json/junit/JSONTokenerTest.java b/src/test/java/org/json/junit/JSONTokenerTest.java index 19c5cdb72..59ca6d8f6 100644 --- a/src/test/java/org/json/junit/JSONTokenerTest.java +++ b/src/test/java/org/json/junit/JSONTokenerTest.java @@ -241,74 +241,74 @@ public void testNextBackComboWithNewLines() { // ^ ^ ^ ^ // index positions 0 8 16 36 final JSONTokener tokener = new JSONTokener(testString); - assertEquals(" at index 0 [character number 1 in line 1]", tokener.toString()); + assertEquals(" at 0 [character 1 line 1]", tokener.toString()); assertEquals('t',tokener.next()); - assertEquals(" at index 1 [character number 2 in line 1]", tokener.toString()); + assertEquals(" at 1 [character 2 line 1]", tokener.toString()); tokener.skipTo('\n'); - assertEquals("skipTo() improperly modifying indexes"," at index 7 [character number 8 in line 1]", tokener.toString()); + assertEquals("skipTo() improperly modifying indexes"," at 7 [character 8 line 1]", tokener.toString()); assertEquals('\n',tokener.next()); - assertEquals(" at index 8 [character number 0 in line 2]", tokener.toString()); + assertEquals(" at 8 [character 0 line 2]", tokener.toString()); assertEquals('A',tokener.next()); - assertEquals(" at index 9 [character number 1 in line 2]", tokener.toString()); + assertEquals(" at 9 [character 1 line 2]", tokener.toString()); tokener.back(); - assertEquals(" at index 8 [character number 0 in line 2]", tokener.toString()); + assertEquals(" at 8 [character 0 line 2]", tokener.toString()); tokener.skipTo('\r'); - assertEquals("skipTo() improperly modifying indexes"," at index 14 [character number 6 in line 2]", tokener.toString()); + assertEquals("skipTo() improperly modifying indexes"," at 14 [character 6 line 2]", tokener.toString()); // verify \r\n combo doesn't increment the line twice assertEquals('\r', tokener.next()); - assertEquals(" at index 15 [character number 0 in line 3]", tokener.toString()); + assertEquals(" at 15 [character 0 line 3]", tokener.toString()); assertEquals('\n', tokener.next()); - assertEquals(" at index 16 [character number 0 in line 3]", tokener.toString()); + assertEquals(" at 16 [character 0 line 3]", tokener.toString()); // verify stepping back after reading the \n of an \r\n combo doesn't increment the line incorrectly tokener.back(); - assertEquals(" at index 15 [character number 6 in line 2]", tokener.toString()); + assertEquals(" at 15 [character 6 line 2]", tokener.toString()); assertEquals('\n', tokener.next()); - assertEquals(" at index 16 [character number 0 in line 3]", tokener.toString()); + assertEquals(" at 16 [character 0 line 3]", tokener.toString()); assertEquals('W', tokener.next()); - assertEquals(" at index 17 [character number 1 in line 3]", tokener.toString()); + assertEquals(" at 17 [character 1 line 3]", tokener.toString()); assertEquals('i', tokener.next()); - assertEquals(" at index 18 [character number 2 in line 3]", tokener.toString()); + assertEquals(" at 18 [character 2 line 3]", tokener.toString()); tokener.skipTo('\r'); - assertEquals("skipTo() improperly modifying indexes"," at index 35 [character number 19 in line 3]", tokener.toString()); + assertEquals("skipTo() improperly modifying indexes"," at 35 [character 19 line 3]", tokener.toString()); assertEquals('\r', tokener.next()); - assertEquals(" at index 36 [character number 0 in line 4]", tokener.toString()); + assertEquals(" at 36 [character 0 line 4]", tokener.toString()); tokener.back(); - assertEquals(" at index 35 [character number 19 in line 3]", tokener.toString()); + assertEquals(" at 35 [character 19 line 3]", tokener.toString()); assertEquals('\r', tokener.next()); - assertEquals(" at index 36 [character number 0 in line 4]", tokener.toString()); + assertEquals(" at 36 [character 0 line 4]", tokener.toString()); assertEquals('N', tokener.next()); - assertEquals(" at index 37 [character number 1 in line 4]", tokener.toString()); + assertEquals(" at 37 [character 1 line 4]", tokener.toString()); // verify we get the same data just walking though, no calls to back final JSONTokener t2 = new JSONTokener(testString); for(int i=0; i<7; i++) { - assertTrue(t2.toString().startsWith(" at index " + i + " ")); + assertTrue(t2.toString().startsWith(" at " + i + " ")); assertEquals(testString.charAt(i), t2.next()); } - assertEquals(" at index 7 [character number 8 in line 1]", t2.toString()); + assertEquals(" at 7 [character 8 line 1]", t2.toString()); assertEquals(testString.charAt(7), t2.next()); - assertEquals(" at index 8 [character number 0 in line 2]", t2.toString()); + assertEquals(" at 8 [character 0 line 2]", t2.toString()); for(int i=8; i<14; i++) { - assertTrue(t2.toString().startsWith(" at index " + i + " ")); + assertTrue(t2.toString().startsWith(" at " + i + " ")); assertEquals(testString.charAt(i), t2.next()); } - assertEquals(" at index 14 [character number 6 in line 2]", t2.toString()); + assertEquals(" at 14 [character 6 line 2]", t2.toString()); assertEquals('\r', t2.next()); - assertEquals(" at index 15 [character number 0 in line 3]", t2.toString()); + assertEquals(" at 15 [character 0 line 3]", t2.toString()); assertEquals('\n', t2.next()); - assertEquals(" at index 16 [character number 0 in line 3]", t2.toString()); + assertEquals(" at 16 [character 0 line 3]", t2.toString()); assertEquals('W', t2.next()); - assertEquals(" at index 17 [character number 1 in line 3]", t2.toString()); + assertEquals(" at 17 [character 1 line 3]", t2.toString()); for(int i=17; i<37; i++) { - assertTrue(t2.toString().startsWith(" at index " + i + " ")); + assertTrue(t2.toString().startsWith(" at " + i + " ")); assertEquals(testString.charAt(i), t2.next()); } - assertEquals(" at index 37 [character number 1 in line 4]", t2.toString()); + assertEquals(" at 37 [character 1 line 4]", t2.toString()); for(int i=37; i