Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-11820] JSONSerialization.data() crashes if I pass in a Nan float #3373

Open
adam-fowler opened this issue Nov 21, 2019 · 1 comment
Open

Comments

@adam-fowler
Copy link
Contributor

Previous ID SR-11820
Radar rdar://problem/57418519
Original Reporter @adam-fowler
Type Bug
Environment

macOS: Catalina 10.15.1

XCode: 11.2.1

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 76516cce1c2232d02dc388d3bc2c4cfc

Issue Description:

If I pass a NaN float to the JSONSerialization.data(withJSONObject:options: ) it crashes. Given that the function throws errors would it not be more sensible for it to throw an "invalid float" error which I could catch.

Example code below crashes instead of the error being handled.

let f: Float = 1.0 / 0.0
let d: [String: Any] = ["tst": f]do {
let data = try JSONSerialization.data(withJSONObject: d, options: [])
    print(String(data: data, encoding: .utf8)!)
} catch {
    print(error)
}
@beccadax
Copy link
Contributor

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants