Revert "Merge pull request #888 from rikkarth/fix/887"

This reverts commit 14f71274f7, reversing
changes made to 054786e300.
This commit is contained in:
Sean Leary
2024-11-03 09:49:23 -06:00
parent 14f71274f7
commit ab1b9a3459
12 changed files with 189 additions and 503 deletions

View File

@@ -216,8 +216,7 @@ public class JSONObjectTest {
* to the spec. However, after being parsed, toString() should emit strictly
* conforming JSON text.
*/
// TODO: This test will only run in non-strictMode. TBD later.
@Ignore
@Test
public void unquotedText() {
String str = "{key1:value1, key2:42, 1.2 : 3.4, -7e5 : something!}";
JSONObject jsonObject = new JSONObject(str);
@@ -1068,8 +1067,7 @@ public class JSONObjectTest {
/**
* This test documents how JSON-Java handles invalid numeric input.
*/
// TODO: to be restored after strictMode parsing is fixed
@Ignore
@Test
public void jsonInvalidNumberValues() {
// Number-notations supported by Java and invalid as JSON
String str =
@@ -2262,7 +2260,7 @@ public class JSONObjectTest {
* Explore how JSONObject handles parsing errors.
*/
@SuppressWarnings({"boxing", "unused"})
@Ignore
@Test
public void jsonObjectParsingErrors() {
try {
// does not start with '{'
@@ -2324,7 +2322,7 @@ public class JSONObjectTest {
assertNull("Expected an exception",new JSONObject(str));
} catch (JSONException e) {
assertEquals("Expecting an exception message",
"Value 'foo' is not surrounded by quotes at 4 [character 5] line 1]",
"Expected a ':' after a key at 5 [character 6 line 1]",
e.getMessage());
}
try {
@@ -3817,33 +3815,27 @@ public class JSONObjectTest {
// Behavior documented in #826 JSONObject parsing 0-led numeric strings as ints
// After reverting the code, personId is stored as a string, and the behavior is as expected
String personId = "\"0123\"";
JSONObject j1 = new JSONObject("{\"personId\": " + personId + "}");
String personId = "0123";
JSONObject j1 = new JSONObject("{personId: " + personId + "}");
assertEquals(j1.getString("personId"), "0123");
// Also #826. Here is input with missing quotes. Because of the leading zero, it should not be parsed as a number.
// This example was mentioned in the same ticket
// After reverting the code, personId is stored as a string, and the behavior is as expected
// TODO: the next two tests fail due to an ambiguity in parsing the value.
// non-StrictMode - it is a valid non-numeric value
// strictMode - Since it is non-numeric, quotes are required.
// This test should be extracted to its own unit test. The result should depend on the strictMode setting.
// For now it s commented out
// JSONObject j2 = new JSONObject("{\"personId\":0123}");
// assertEquals(j2.getString("personId"), "0123");
JSONObject j2 = new JSONObject("{\"personId\":0123}");
assertEquals(j2.getString("personId"), "0123");
// Behavior uncovered while working on the code
// All of the values are stored as strings except for hex4, which is stored as a number. This is probably incorrect
// JSONObject j3 = new JSONObject("{ " +
// "\"hex1\": \"010e4\", \"hex2\": \"00f0\", \"hex3\": \"0011\", " +
// "\"hex4\": 00e0, \"hex5\": 00f0, \"hex6\": 0011 }");
// assertEquals(j3.getString("hex1"), "010e4");
// assertEquals(j3.getString("hex2"), "00f0");
// assertEquals(j3.getString("hex3"), "0011");
// assertEquals(j3.getLong("hex4"), 0, .1);
// assertEquals(j3.getString("hex5"), "00f0");
// assertEquals(j3.getString("hex6"), "0011");
JSONObject j3 = new JSONObject("{ " +
"\"hex1\": \"010e4\", \"hex2\": \"00f0\", \"hex3\": \"0011\", " +
"\"hex4\": 00e0, \"hex5\": 00f0, \"hex6\": 0011 }");
assertEquals(j3.getString("hex1"), "010e4");
assertEquals(j3.getString("hex2"), "00f0");
assertEquals(j3.getString("hex3"), "0011");
assertEquals(j3.getLong("hex4"), 0, .1);
assertEquals(j3.getString("hex5"), "00f0");
assertEquals(j3.getString("hex6"), "0011");
}
/**