Skip to content

Commit 07b1291

Browse files
authored
Merge pull request #942 from michael-ameri/fix-clone
add missing fields when cloning JSONParserConfiguration
2 parents 1d81e88 + 4bbbe77 commit 07b1291

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/main/java/org/json/JSONParserConfiguration.java

+2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ public JSONParserConfiguration() {
2727
protected JSONParserConfiguration clone() {
2828
JSONParserConfiguration clone = new JSONParserConfiguration();
2929
clone.overwriteDuplicateKey = overwriteDuplicateKey;
30+
clone.strictMode = strictMode;
3031
clone.maxNestingDepth = maxNestingDepth;
32+
clone.keepStrings = keepStrings;
3133
return clone;
3234
}
3335

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
import java.util.stream.Collectors;
1616
import java.util.stream.Stream;
1717

18-
import static org.junit.Assert.*;
18+
import static org.junit.Assert.assertEquals;
19+
import static org.junit.Assert.assertThrows;
20+
import static org.junit.Assert.assertTrue;
21+
import static org.junit.Assert.fail;
1922

2023
public class JSONParserConfigurationTest {
2124
private static final String TEST_SOURCE = "{\"key\": \"value1\", \"key\": \"value2\"}";
@@ -33,6 +36,24 @@ public void testOverwrite() {
3336
assertEquals("duplicate key should be overwritten", "value2", jsonObject.getString("key"));
3437
}
3538

39+
@Test
40+
public void strictModeIsCloned(){
41+
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
42+
.withStrictMode(true)
43+
.withMaxNestingDepth(12);
44+
45+
assertTrue(jsonParserConfiguration.isStrictMode());
46+
}
47+
48+
@Test
49+
public void maxNestingDepthIsCloned(){
50+
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
51+
.<JSONParserConfiguration>withKeepStrings(true)
52+
.withStrictMode(true);
53+
54+
assertTrue(jsonParserConfiguration.isKeepStrings());
55+
}
56+
3657
@Test
3758
public void verifyDuplicateKeyThenMaxDepth() {
3859
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()

0 commit comments

Comments
 (0)