Skip to content

Commit cad389b

Browse files
authored
StreamReadConstraints can use same digits limit like play-json internally uses (#1254)
1 parent 02f89b0 commit cad389b

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

play-json/jvm/src/main/scala/play/api/libs/json/JsonConfig.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ object JsonConfig {
216216
.builder()
217217
.maxNestingDepth(loadMaxNestingDepth)
218218
.maxStringLength(loadMaxStringLength)
219-
.maxNumberLength(Int.MaxValue) // play-json has its own support for limiting number length
219+
.maxNumberLength(loadDigitsLimit) // play-json has its own support for limiting number length
220220
.build()
221221

222222
private[json] val defaultStreamWriteConstraints: StreamWriteConstraints =

play-json/jvm/src/test/scala/play/api/libs/json/JsonSpec.scala

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,29 @@ class JsonSpec extends org.specs2.mutable.Specification {
429429
}
430430

431431
"fail when exceeding the number of digits limit for positive numbers" in {
432-
Json.parse(invalidJsonExceedingNumberOfDigits).as[BigNumbers].must(throwA[IllegalArgumentException])
432+
Json
433+
.parse(invalidJsonExceedingNumberOfDigits)
434+
.as[BigNumbers]
435+
.must(throwA[StreamConstraintsException].like { case e: StreamConstraintsException =>
436+
e.getMessage.must(
437+
equalTo(
438+
"Number value length (1000000) exceeds the maximum allowed (310, from `StreamReadConstraints.getMaxNumberLength()`)"
439+
)
440+
)
441+
})
433442
}
434443

435444
"fail when exceeding the number of digits limit for negative numbers" in {
436-
Json.parse(invalidJsonExceedingNumberOfDigitsNegative).as[BigNumbers].must(throwA[IllegalArgumentException])
445+
Json
446+
.parse(invalidJsonExceedingNumberOfDigitsNegative)
447+
.as[BigNumbers]
448+
.must(throwA[StreamConstraintsException].like { case e: StreamConstraintsException =>
449+
e.getMessage.must(
450+
equalTo(
451+
"Number value length (1000000) exceeds the maximum allowed (310, from `StreamReadConstraints.getMaxNumberLength()`)"
452+
)
453+
)
454+
})
437455
}
438456
}
439457
}

0 commit comments

Comments
 (0)