Skip to content

Commit 3bc9d16

Browse files
authored
Added json parser tests with stackoverflow.
1 parent 6954e93 commit 3bc9d16

File tree

3 files changed

+1668
-0
lines changed

3 files changed

+1668
-0
lines changed

src/test/java/com/github/underscore/StringTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232

3333
import com.github.underscore.Json.JsonStringBuilder;
3434
import com.github.underscore.Xml.XmlStringBuilder;
35+
36+
import java.io.IOException;
37+
import java.nio.file.Files;
38+
import java.nio.file.Paths;
3539
import java.util.ArrayList;
3640
import java.util.Arrays;
3741
import java.util.Collection;
@@ -3424,6 +3428,26 @@ void fromJsonMap() {
34243428
assertEquals("{}", U.fromJsonMap(stringJson2).toString());
34253429
}
34263430

3431+
@Test
3432+
void fromJsonStackoverflowObject() throws IOException {
3433+
String stringJson = new String(Files.readAllBytes(Paths.get("src/test/resources/wellFormedObject.json")));
3434+
try {
3435+
U.fromJsonMap(stringJson);
3436+
} catch (Throwable throwable) {
3437+
assertTrue(throwable instanceof StackOverflowError);
3438+
}
3439+
}
3440+
3441+
@Test
3442+
void fromJsonStackoverflowArray() throws IOException {
3443+
String stringJson = new String(Files.readAllBytes(Paths.get("src/test/resources/wellFormedArray.json")));
3444+
try {
3445+
U.fromJsonMap(stringJson);
3446+
} catch (Throwable throwable) {
3447+
assertTrue(throwable instanceof StackOverflowError);
3448+
}
3449+
}
3450+
34273451
@Test
34283452
void testDecodeParseXmlErr13() {
34293453
assertThrows(IllegalArgumentException.class, () -> U.fromXml("[\"abc\u0010\"]"));

0 commit comments

Comments
 (0)