Skip to content

Commit eb56704

Browse files
committed
fix: set default maximum nesting depth as 512
1 parent 651511f commit eb56704

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/main/java/org/json/XMLParserConfiguration.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public class XMLParserConfiguration {
2222
*/
2323
public static final int UNDEFINED_MAXIMUM_NESTING_DEPTH = -1;
2424

25+
/**
26+
* The default maximum nesting depth when parsing a XML document to JSON.
27+
*/
28+
public static final int DEFAULT_MAXIMUM_NESTING_DEPTH = 512;
29+
2530
/** Original Configuration of the XML Parser. */
2631
public static final XMLParserConfiguration ORIGINAL
2732
= new XMLParserConfiguration();
@@ -64,7 +69,7 @@ public class XMLParserConfiguration {
6469
* When parsing the XML into JSON, specifies the tags whose values should be converted
6570
* to arrays
6671
*/
67-
private int maxNestingDepth = UNDEFINED_MAXIMUM_NESTING_DEPTH;
72+
private int maxNestingDepth = DEFAULT_MAXIMUM_NESTING_DEPTH;
6873

6974
/**
7075
* Default parser configuration. Does not keep strings (tries to implicitly convert
@@ -321,8 +326,8 @@ public int getMaxNestingDepth() {
321326

322327
/**
323328
* Defines the maximum nesting depth that the parser will descend before throwing an exception
324-
* when parsing the XML into JSON. The default max nesting depth is undefined, which means the
325-
* parser will go as deep as the maximum call stack size allows. Using any negative value as a
329+
* when parsing the XML into JSON. The default max nesting depth is 512, which means the parser
330+
* will go as deep as the maximum call stack size allows. Using any negative value as a
326331
* parameter is equivalent to setting no limit to the nesting depth.
327332
* @param maxNestingDepth the maximum nesting depth allowed to the XML parser
328333
* @return The existing configuration will not be modified. A new configuration is returned.

src/test/java/org/json/junit/JSONArrayTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import static org.junit.Assert.assertEquals;
88
import static org.junit.Assert.assertFalse;
9-
import static org.junit.Assert.assertNotEquals;
109
import static org.junit.Assert.assertNotNull;
1110
import static org.junit.Assert.assertNull;
1211
import static org.junit.Assert.assertTrue;

src/test/java/org/json/junit/XMLConfigurationTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ public void testEmptyTagForceList() {
10561056
public void testMaxNestingDepthIsSet() {
10571057
XMLParserConfiguration xmlParserConfiguration = XMLParserConfiguration.ORIGINAL;
10581058

1059-
assertEquals(xmlParserConfiguration.getMaxNestingDepth(), XMLParserConfiguration.UNDEFINED_MAXIMUM_NESTING_DEPTH);
1059+
assertEquals(xmlParserConfiguration.getMaxNestingDepth(), XMLParserConfiguration.DEFAULT_MAXIMUM_NESTING_DEPTH);
10601060

10611061
xmlParserConfiguration = xmlParserConfiguration.withMaxNestingDepth(42);
10621062

0 commit comments

Comments
 (0)