Skip to content

Commit

Permalink
negative integer with more than one digit can't start with 0
Browse files Browse the repository at this point in the history
  • Loading branch information
konnik committed Sep 19, 2023
1 parent 6d3c692 commit a6a9752
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/src/main/kotlin/konnik/json/JsonParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private val integer: Parser<String> = oneOf(
onenine + digits,
digit,
s("-") + onenine + digits,
s("-") + digits,
s("-") + digit,
)

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/src/test/kotlin/konnik/json/JsonParserKtTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class JsonParserKtTest {

@Test
fun `numbers - invalid ones`() {
assertEquals(null, parseJson("0123")) // cant start with 0
assertEquals(null, parseJson("0123")) // cant start with 0 if more than one digit
assertEquals(null, parseJson("-0123")) // negative numbers with more than on digit can't start with 0
assertEquals(null, parseJson(".123")) // must have number before decimal point
assertEquals(null, parseJson("+12")) // positive numbers does not use prefix +
}
Expand Down

0 comments on commit a6a9752

Please sign in to comment.