Skip to content

Commit b136245

Browse files
committed
Always throw JsonReaderException when reading invalid java.time.LocalTime and java.time.LocalDateTime values with JVMs or Scala Native
1 parent 3a005fa commit b136245

File tree

3 files changed

+7
-5
lines changed
  • jsoniter-scala-core

3 files changed

+7
-5
lines changed

jsoniter-scala-core/jvm/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/JsonReader.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3126,7 +3126,7 @@ final class JsonReader private[jsoniter_scala](
31263126
hour < 24
31273127
} || m << 16 == 0xE800000000000000L && {
31283128
pos += 5
3129-
hour <= 24
3129+
hour < 24
31303130
}
31313131
}) {
31323132
b = buf(pos)
@@ -3203,7 +3203,7 @@ final class JsonReader private[jsoniter_scala](
32033203
hour < 24
32043204
} || m << 16 == 0xE800000000000000L && {
32053205
pos += 5
3206-
hour <= 24
3206+
hour < 24
32073207
}
32083208
}) {
32093209
b = buf(pos)

jsoniter-scala-core/native/src/main/scala/com/github/plokhotnyuk/jsoniter_scala/core/JsonReader.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3122,7 +3122,7 @@ final class JsonReader private[jsoniter_scala](
31223122
hour < 24
31233123
} || m << 16 == 0xE800000000000000L && {
31243124
pos += 5
3125-
hour <= 24
3125+
hour < 24
31263126
}
31273127
}) {
31283128
b = buf(pos)
@@ -3199,7 +3199,7 @@ final class JsonReader private[jsoniter_scala](
31993199
hour < 24
32003200
} || m << 16 == 0xE800000000000000L && {
32013201
pos += 5
3202-
hour <= 24
3202+
hour < 24
32033203
}
32043204
}) {
32053205
b = buf(pos)

jsoniter-scala-core/shared/src/test/scala/com/github/plokhotnyuk/jsoniter_scala/core/JsonReaderSpec.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,7 @@ class JsonReaderSpec extends AnyWordSpec with Matchers with ScalaCheckPropertyCh
11431143
assert(intercept[JsonReaderException](reader(json).readKeyAsLocalDateTime()).getMessage.startsWith(error))
11441144
}
11451145

1146+
checkError(""""2008-01-20T24:24" """, "illegal hour, offset: 0x0000000d")
11461147
checkError(""""""", "unexpected end of input, offset: 0x00000001")
11471148
checkError(""""2008-01-20T07:24:33""", "unexpected end of input, offset: 0x00000014")
11481149
checkError(""""+1000000000-01-20T07:24:33"""", "expected '-', offset: 0x0000000b")
@@ -1247,12 +1248,13 @@ class JsonReaderSpec extends AnyWordSpec with Matchers with ScalaCheckPropertyCh
12471248
reader(s"""$ws"$s":$ws""").readKeyAsLocalTime() shouldBe x
12481249
}
12491250
}
1250-
"throw parsing exception for empty input and illegal or broken LocalDateTime string" in {
1251+
"throw parsing exception for empty input and illegal or broken LocalTime string" in {
12511252
def checkError(json: String, error: String): Unit = {
12521253
assert(intercept[JsonReaderException](reader(json).readLocalTime(null)).getMessage.startsWith(error))
12531254
assert(intercept[JsonReaderException](reader(json).readKeyAsLocalTime()).getMessage.startsWith(error))
12541255
}
12551256

1257+
checkError(""""24:24" """, "illegal hour, offset: 0x00000002")
12561258
checkError(""""""", "unexpected end of input, offset: 0x00000001")
12571259
checkError(""""07:24:33""", "unexpected end of input, offset: 0x00000009")
12581260
checkError(""""24:24:33"""", "illegal hour, offset: 0x00000002")

0 commit comments

Comments
 (0)