Skip to content

Decode an optional URL throws an error #4684

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

Closed
azone opened this issue Jan 11, 2023 · 1 comment
Closed

Decode an optional URL throws an error #4684

azone opened this issue Jan 11, 2023 · 1 comment

Comments

@azone
Copy link

azone commented Jan 11, 2023

https://github.com/apple/swift-corelibs-foundation/blob/f42e9af210a4cddba7b176165c005ffac5685a68/Sources/Foundation/URL.swift#L1041

struct Test: Codable {
    let url: URL?
}

let data = """
{"url": ""}
""".data(using: .utf8)!
// decode
let decoder = JSONDecoder()
do {
    let s = try decoder.decode(Test.self, from: data)
} catch {
    // will throw "Invalid URL string." error
}
@parkera
Copy link
Contributor

parkera commented Jul 5, 2024

This seems to be working for me as of the 6.0 branch. It may also be related to #5001

@parkera parkera closed this as not planned Won't fix, can't repro, duplicate, stale Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants