File tree 2 files changed +10
-1
lines changed
2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -404,7 +404,7 @@ extension JSONDecoderImpl: Decoder {
404
404
as type: T . Type ) throws -> T
405
405
{
406
406
if case . number( let number) = value {
407
- guard let floatingPoint = T ( number) else {
407
+ guard let floatingPoint = T ( number) , floatingPoint . isFinite else {
408
408
var path = self . codingPath
409
409
if let additionalKey = additionalKey {
410
410
path. append ( additionalKey)
Original file line number Diff line number Diff line change @@ -601,14 +601,23 @@ class TestJSONEncoder : XCTestCase {
601
601
602
602
func test_codingOfFloat( ) {
603
603
test_codingOf ( value: Float ( 1.5 ) , toAndFrom: " 1.5 " )
604
+
605
+ // Check value too large fails to decode.
606
+ XCTAssertThrowsError ( try JSONDecoder ( ) . decode ( Float . self, from: " 1e100 " . data ( using: . utf8) !) )
604
607
}
605
608
606
609
func test_codingOfDouble( ) {
607
610
test_codingOf ( value: Double ( 1.5 ) , toAndFrom: " 1.5 " )
611
+
612
+ // Check value too large fails to decode.
613
+ XCTAssertThrowsError ( try JSONDecoder ( ) . decode ( Double . self, from: " 100e323 " . data ( using: . utf8) !) )
608
614
}
609
615
610
616
func test_codingOfDecimal( ) {
611
617
test_codingOf ( value: Decimal . pi, toAndFrom: " 3.14159265358979323846264338327950288419 " )
618
+
619
+ // Check value too large fails to decode.
620
+ XCTAssertThrowsError ( try JSONDecoder ( ) . decode ( Decimal . self, from: " 100e200 " . data ( using: . utf8) !) )
612
621
}
613
622
614
623
func test_codingOfString( ) {
You can’t perform that action at this time.
0 commit comments