Skip to content

Commit 4bbbe77

Browse files
committed
add missing fields when cloning
1 parent 391c869 commit 4bbbe77

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
import java.util.stream.Collectors;
1515
import java.util.stream.Stream;
1616

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

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

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

0 commit comments

Comments
 (0)