From a6a97525f5abd2894cdee37321401bf2795ee893 Mon Sep 17 00:00:00 2001 From: konnik Date: Tue, 19 Sep 2023 09:56:40 +0200 Subject: [PATCH] negative integer with more than one digit can't start with 0 --- lib/src/main/kotlin/konnik/json/JsonParser.kt | 2 +- lib/src/test/kotlin/konnik/json/JsonParserKtTest.kt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/src/main/kotlin/konnik/json/JsonParser.kt b/lib/src/main/kotlin/konnik/json/JsonParser.kt index 31d172e..1d4e819 100644 --- a/lib/src/main/kotlin/konnik/json/JsonParser.kt +++ b/lib/src/main/kotlin/konnik/json/JsonParser.kt @@ -228,7 +228,7 @@ private val integer: Parser = oneOf( onenine + digits, digit, s("-") + onenine + digits, - s("-") + digits, + s("-") + digit, ) /** diff --git a/lib/src/test/kotlin/konnik/json/JsonParserKtTest.kt b/lib/src/test/kotlin/konnik/json/JsonParserKtTest.kt index a1fd907..f6b2cea 100644 --- a/lib/src/test/kotlin/konnik/json/JsonParserKtTest.kt +++ b/lib/src/test/kotlin/konnik/json/JsonParserKtTest.kt @@ -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 + }