swiftlang / swift-foundation

The Foundation project
Apache License 2.0
2.4k stars 160 forks source link

rdar://133742708 (JSONDecoder crashes whole app on invalid input instead of throwing Error) #1043

Closed kperryua closed 1 day ago

kperryua commented 1 day ago

These try! assertions were incorrect. They were focused on the fact that the type of the value in the input JSON was guaranteed to be a string, but with the on-demand parsing behavior, there is no longer any initial UTF-8 validation step, which means decoding the keys into String values could fail. This needs to actually throw an error instead of trapping. Fortunately, this is an (embarrassingly) easy change to make.

kperryua commented 1 day ago

@swift-ci Please test