Compare commits

...
Author SHA1 Message Date
Sean Leary 6c14048079 Merge pull request #1073 from stleary/pre-release-20260814
20260814 prep for next release
2026-08-14 11:09:30 -05:00
Sean Leary 34efda6423 pre-release-20260814 initial commit 2026-08-14 10:54:22 -05:00
Sean Leary 22ab2fb724 Update jar file link in README 2026-07-31 15:28:31 -05:00
Sean Leary 392a352901 Fix formatting of the latest release jar file link 2026-07-31 15:26:28 -05:00
Sean Leary b594a3229c Merge pull request #1070 from dong0713/fix/xml-unescape-whitespace-control-chars
Fix XML.unescape rejecting valid whitespace numeric character references
2026-07-29 07:50:07 -05:00
dong0713 94854a1dfa Fix XML.unescape rejecting valid whitespace numeric character references
XML.mustEscape() is shared by both XML.escape() (serialization) and
XMLTokener.unescapeEntity() (deserialization). While the method's Javadoc
and comment quote the W3C XML 1.0 valid-character range
(#x9 | #xA | #xD | [#x20-#xD7FF] | ...), the implementation only checked
[#x20-#xD7FF] in its range clause, omitting #x9/#xA/#xD.

Although the ISO-control clause excluded those three codepoints, the
negated range clause still marked them as 'must escape', so unescapeEntity()
threw JSONException for the XML-allowed control characters TAB, LF and CR.

This broke XML.unescape("&#10;") and XML.toJSONObject("<a>&#10;</a>"),
both of which worked in v20251224 and regressed after #1045 (v20260522).

Align the range clause with the W3C spec by explicitly allowing #x9, #xA
and #xD, matching the comment that was already documented.

Fixes #1059
2026-07-20 17:42:02 +08:00
Sean Leary 1795e8cf26 Merge pull request #1069 from stleary/pre-release-20260719
20260719 prep for next release
2026-07-19 14:04:18 -05:00
Sean Leary da757c6656 pre-release-20260719 oops forgot to update new unit tests for strict mode 2026-07-19 13:48:18 -05:00
Sean Leary d24bc9e5d6 pre-release-20260719 initial commit 2026-07-19 12:51:08 -05:00
Sean Leary 80efb529d7 Merge pull request #1068 from stleary/max-number-length-config
Max number length config for BigInteger and BigDecimal
2026-07-19 12:43:09 -05:00
7 changed files with 117 additions and 59 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ JSON in Java [package org.json]
[![CodeQL](https://github.com/stleary/JSON-java/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/stleary/JSON-java/actions/workflows/codeql-analysis.yml) [![CodeQL](https://github.com/stleary/JSON-java/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/stleary/JSON-java/actions/workflows/codeql-analysis.yml)
[![javadoc](https://javadoc.io/badge2/org.json/json/javadoc.svg)](https://javadoc.io/doc/org.json/json) [![javadoc](https://javadoc.io/badge2/org.json/json/javadoc.svg)](https://javadoc.io/doc/org.json/json)
**[Click here if you just want the latest release jar file.](https://search.maven.org/remotecontent?filepath=org/json/json/20260522/json-20260522.jar)** **[Click here if you just want the latest release jar file.](https://repo1.maven.org/maven2/org/json/json/20260814/json-20260814.jar)**
# Overview # Overview
+9 -1
View File
@@ -21,6 +21,7 @@ repositories {
} }
// To view the report open build/reports/jacoco/test/html/index.html // To view the report open build/reports/jacoco/test/html/index.html
// Note: disable jacocoTestReport and test blocks, and the jacoco plugin if it interferes with stepping in the debugger
jacocoTestReport { jacocoTestReport {
reports { reports {
html.required = true html.required = true
@@ -31,6 +32,13 @@ test {
finalizedBy jacocoTestReport finalizedBy jacocoTestReport
} }
// enable logging to stdout during test
tasks.withType(Test) {
testLogging {
showStandardStreams = true
}
}
dependencies { dependencies {
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
testImplementation 'com.jayway.jsonpath:json-path:2.9.0' testImplementation 'com.jayway.jsonpath:json-path:2.9.0'
@@ -42,7 +50,7 @@ subprojects {
} }
group = 'org.json' group = 'org.json'
version = 'v20260522-SNAPSHOT' version = 'v20260814-SNAPSHOT'
description = 'JSON in Java' description = 'JSON in Java'
sourceCompatibility = '1.8' sourceCompatibility = '1.8'
+4
View File
@@ -5,6 +5,10 @@ and artifactId "json". For example:
[https://search.maven.org/search?q=g:org.json%20AND%20a:json&core=gav](https://search.maven.org/search?q=g:org.json%20AND%20a:json&core=gav) [https://search.maven.org/search?q=g:org.json%20AND%20a:json&core=gav](https://search.maven.org/search?q=g:org.json%20AND%20a:json&core=gav)
~~~ ~~~
20260814 Fixes XML.unescape whitespace handling
20260719 Fixes CVE-2026-59171 very large BigInteger, BigDecimal
20260522 Publish key data, recent commits for minor fixes 20260522 Publish key data, recent commits for minor fixes
20251224 Records, fromJson(), and recent commits 20251224 Records, fromJson(), and recent commits
+2 -26
View File
@@ -3,7 +3,7 @@
<groupId>org.json</groupId> <groupId>org.json</groupId>
<artifactId>json</artifactId> <artifactId>json</artifactId>
<version>20260522</version> <version>20260814</version>
<packaging>bundle</packaging> <packaging>bundle</packaging>
<name>JSON in Java</name> <name>JSON in Java</name>
@@ -46,20 +46,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<distributionManagement>
<repository>
<id>ossrh</id>
<name>Central Repository OSSRH</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
<snapshotRepository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
@@ -158,17 +144,7 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.3</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>false</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.moditect</groupId> <groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId> <artifactId>moditect-maven-plugin</artifactId>
+8 -2
View File
@@ -172,8 +172,14 @@ public class XML {
&& cp != 0xA && cp != 0xA
&& cp != 0xD && cp != 0xD
) || !( ) || !(
// valid the range of acceptable characters that aren't control // Valid character range per W3C XML 1.0 spec:
(cp >= 0x20 && cp <= 0xD7FF) // #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
// Previously omitted #x9/#xA/#xD, causing unescape("&#10;") etc.
// to reject valid LF/TAB/CR as illegal (see #1059)
cp == 0x9
|| cp == 0xA
|| cp == 0xD
|| (cp >= 0x20 && cp <= 0xD7FF)
|| (cp >= 0xE000 && cp <= 0xFFFD) || (cp >= 0xE000 && cp <= 0xFFFD)
|| (cp >= 0x10000 && cp <= 0x10FFFF) || (cp >= 0x10000 && cp <= 0x10FFFF)
) )
@@ -3885,6 +3885,7 @@ public class JSONObjectTest {
@Test @Test
public void testMaxNumberLength() { public void testMaxNumberLength() {
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i = 0; i < 100; ++i) { for (int i = 0; i < 100; ++i) {
sb.append("9999999999"); sb.append("9999999999");
@@ -3896,11 +3897,14 @@ public class JSONObjectTest {
// JSONArray with number just under the max length limit // JSONArray with number just under the max length limit
checkJSONArrayMaxLen(sb.toString(), true, null); checkJSONArrayMaxLen(sb.toString(), true, null);
// numbers without quotes are not allowed in strict mode
if (!jsonParserConfiguration.isStrictMode()) {
// JSONObject with number just over the max length limit // JSONObject with number just over the max length limit
checkJSONObjectMaxLen(sb + "9", false, null); checkJSONObjectMaxLen(sb + "9", false, null);
// JSONArray with number just over the max length limit // JSONArray with number just over the max length limit
checkJSONArrayMaxLen(sb + "9", false, null); checkJSONArrayMaxLen(sb + "9", false, null);
}
// JSONObject with number at config max length limit // JSONObject with number at config max length limit
checkJSONObjectMaxLen(sb.toString() + sb.toString(), true, new JSONParserConfiguration().withMaxNumberLength(2000)); checkJSONObjectMaxLen(sb.toString() + sb.toString(), true, new JSONParserConfiguration().withMaxNumberLength(2000));
@@ -3908,11 +3912,14 @@ public class JSONObjectTest {
// JSONArray with number at config max length limit // JSONArray with number at config max length limit
checkJSONArrayMaxLen((sb.toString() + sb), true, new JSONParserConfiguration().withMaxNumberLength(2000)); checkJSONArrayMaxLen((sb.toString() + sb), true, new JSONParserConfiguration().withMaxNumberLength(2000));
// numbers without quotes are not allowed in strict mode
if (!jsonParserConfiguration.isStrictMode()) {
// JSONObject with number just over config max length limit // JSONObject with number just over config max length limit
checkJSONObjectMaxLen(sb.toString() + sb.toString() + "9", false, new JSONParserConfiguration().withMaxNumberLength(2000)); checkJSONObjectMaxLen(sb.toString() + sb.toString() + "9", false, new JSONParserConfiguration().withMaxNumberLength(2000));
// JSONArray with number just over config max length limit // JSONArray with number just over config max length limit
checkJSONArrayMaxLen((sb.toString() + sb + "9"), false, new JSONParserConfiguration().withMaxNumberLength(2000)); checkJSONArrayMaxLen((sb.toString() + sb + "9"), false, new JSONParserConfiguration().withMaxNumberLength(2000));
}
// JSONObject with large number, no checks // JSONObject with large number, no checks
checkJSONObjectMaxLen(sb.toString() + sb.toString() + "9", true, checkJSONObjectMaxLen(sb.toString() + sb.toString() + "9", true,
@@ -3975,6 +3982,8 @@ public class JSONObjectTest {
*/ */
@Test @Test
public void testMaxNumberLengthNegativeInteger() { public void testMaxNumberLengthNegativeInteger() {
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration();
// Build a negative number string of exactly 1000 chars: "-" + 999 digits // Build a negative number string of exactly 1000 chars: "-" + 999 digits
StringBuilder sb = new StringBuilder("-"); StringBuilder sb = new StringBuilder("-");
for (int i = 0; i < 999; ++i) { for (int i = 0; i < 999; ++i) {
@@ -3985,17 +3994,22 @@ public class JSONObjectTest {
// at max length: parsed as number // at max length: parsed as number
checkJSONObjectMaxLen(sb.toString(), true, null); checkJSONObjectMaxLen(sb.toString(), true, null);
// numbers without quotes are not allowed in strict mode
if (!jsonParserConfiguration.isStrictMode()) {
// over max length: returned as string // over max length: returned as string
sb.append("1"); sb.append("1");
assertEquals(1001, sb.length()); assertEquals(1001, sb.length());
checkJSONObjectMaxLen(sb.toString(), false, null); checkJSONObjectMaxLen(sb.toString(), false, null);
} }
}
/** /**
* Test max number length for decimal notation strings via stringToValue. * Test max number length for decimal notation strings via stringToValue.
*/ */
@Test @Test
public void testMaxNumberLengthDecimal() { public void testMaxNumberLengthDecimal() {
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration();
// Build a decimal number string of exactly 1000 chars: 499 digits + "." + 500 // Build a decimal number string of exactly 1000 chars: 499 digits + "." + 500
// digits // digits
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@@ -4011,17 +4025,22 @@ public class JSONObjectTest {
// at max length: parsed as number (BigDecimal) // at max length: parsed as number (BigDecimal)
checkJSONObjectMaxLen(sb.toString(), true, null); checkJSONObjectMaxLen(sb.toString(), true, null);
// numbers without quotes are not allowed in strict mode
if (!jsonParserConfiguration.isStrictMode()) {
// over max length: returned as string // over max length: returned as string
sb.append("3"); sb.append("3");
assertEquals(1001, sb.length()); assertEquals(1001, sb.length());
checkJSONObjectMaxLen(sb.toString(), false, null); checkJSONObjectMaxLen(sb.toString(), false, null);
} }
}
/** /**
* Test max number length with scientific notation via stringToValue. * Test max number length with scientific notation via stringToValue.
*/ */
@Test @Test
public void testMaxNumberLengthScientificNotation() { public void testMaxNumberLengthScientificNotation() {
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration();
// Build a scientific notation string of exactly 1000 chars // Build a scientific notation string of exactly 1000 chars
StringBuilder sb = new StringBuilder("1."); StringBuilder sb = new StringBuilder("1.");
for (int i = 0; i < 994; ++i) { for (int i = 0; i < 994; ++i) {
@@ -4038,10 +4057,14 @@ public class JSONObjectTest {
for (int i = 0; i < 995; ++i) { for (int i = 0; i < 995; ++i) {
sb.append("0"); sb.append("0");
} }
// numbers without quotes are not allowed in strict mode
if (!jsonParserConfiguration.isStrictMode()) {
sb.append("e100"); sb.append("e100");
assertEquals(1001, sb.length()); assertEquals(1001, sb.length());
checkJSONObjectMaxLen(sb.toString(), false, null); checkJSONObjectMaxLen(sb.toString(), false, null);
} }
}
/** /**
* Test that optBigDecimal enforces max number length for string values. * Test that optBigDecimal enforces max number length for string values.
@@ -4297,6 +4320,9 @@ public class JSONObjectTest {
*/ */
@Test @Test
public void testStringToNumberInvalidFormats() { public void testStringToNumberInvalidFormats() {
// this test should only run in non-strict mode, otherwise it will throw an exception
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration();
if (!jsonParserConfiguration.isStrictMode()) {
// Leading zero followed by digit → treated as string (not octal) // Leading zero followed by digit → treated as string (not octal)
JSONObject jo = new JSONObject("{\"a\": 01}"); JSONObject jo = new JSONObject("{\"a\": 01}");
// JSONTokener with strict mode would reject, but default mode stores as string // JSONTokener with strict mode would reject, but default mode stores as string
@@ -4309,5 +4335,6 @@ public class JSONObjectTest {
val = jo.get("a"); val = jo.get("a");
assertTrue("-01 should be stored as string, got " + val.getClass(), val instanceof String); assertTrue("-01 should be stored as string, got " + val.getClass(), val instanceof String);
} }
}
} }
+37
View File
@@ -1537,6 +1537,43 @@ public class XMLTest {
assertEquals("A", jsonObject.getString("a")); assertEquals("A", jsonObject.getString("a"));
} }
/**
* Tests that valid XML numeric character references for whitespace
* control characters (TAB, LF, CR) are correctly unescaped. These
* codepoints are explicitly allowed by the XML 1.0 spec
* (https://www.w3.org/TR/REC-xml/#charsets) but were previously rejected
* as invalid. See issue #1059.
*/
@Test
public void testValidWhitespaceNumericEntityUnescape() {
// decimal references for the three allowed control characters
assertEquals("\t", XML.unescape("&#9;"));
assertEquals("\n", XML.unescape("&#10;"));
assertEquals("\r", XML.unescape("&#13;"));
// hex references for the same codepoints
assertEquals("\t", XML.unescape("&#x9;"));
assertEquals("\n", XML.unescape("&#xA;"));
assertEquals("\r", XML.unescape("&#xD;"));
}
/**
* Tests that {@code XML.toJSONObject} accepts numeric character references
* for the XML-allowed control characters (TAB, LF, CR) without throwing.
* Regression test for #1059, where {@code XML.toJSONObject("<a>&#10;</a>")}
* threw JSONException in versions after 20251224.
*/
@Test
public void testValidWhitespaceNumericEntityToJSONObject() {
// LF reference should round-trip through toJSONObject without throwing
JSONObject jsonObject = XML.toJSONObject("<a>&#10;</a>");
// the value is the LF character (possibly trimmed by the JSON path,
// but the call must not throw)
assertTrue(jsonObject.has("a"));
// TAB and CR references also accepted
XML.toJSONObject("<a>&#9;</a>");
XML.toJSONObject("<a>&#13;</a>");
}
} }