Skip to content

Commit

Permalink
fix bug in nesting level counting
Browse files Browse the repository at this point in the history
  • Loading branch information
erosb committed Oct 30, 2024
1 parent 37ae35b commit 77db601
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/com/github/erosb/jsonsKema/JsonParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class JsonParser private constructor(
if (jsonValue == null) {
throw JsonParseException("unexpected character $curr", sourceLocation())
}
--currentNestingDepth
walker.skipWhitespaces()
return jsonValue
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/kotlin/com/github/erosb/jsonsKema/JsonParserTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ class JsonParserTest {
assertThat(actual.message).isEqualTo("too deeply nested json value at line 6, character 21. Maximum nesting level in json structures is 5.")
}

@Test
fun `not too deep nesting`() {
JsonParser(
"""
[
{
"a": [
]
},
[],
[],
[],
[]
]
""".trimIndent(), DEFAULT_BASE_URI, 5
)()
}

@Test
fun `null token mismatch`() {
val exception = assertThrows(JsonParseException::class.java) {
Expand Down

0 comments on commit 77db601

Please sign in to comment.