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-15508] URL.path is empty if the path contains percent-encoded non-UTF8 bytes #3353

Open
karwa opened this issue Nov 22, 2021 · 1 comment

Comments

@karwa
Copy link
Contributor

karwa commented Nov 22, 2021

Previous ID SR-15508
Radar None
Original Reporter @karwa
Type Bug
Environment

macOS 11.6, Xcode 13.1 (13A1030d)

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

md5: 03f9ee3f9bfabb2973b3364825b0287d

Issue Description:

import Foundation

let urlA = URL(string: "s://s/somepath/%72")!
print(urlA.path) // "/somepath/r"

let urlB = URL(string: "s://s/somepath/%82")!
print(urlB.path) // ""

This is very surprising. It seems NSURL.path copies the filesystem path in POSIX-style, which I'm guessing does some additional validation of the percent-decoded bytes.

The result is that a path containing invalid UTF-8 appears to be completely empty. It doesn't even have any Unicode replacement characters letting you know something didn't decode properly.

@karwa
Copy link
Contributor Author

karwa commented Nov 22, 2021

Also, the same is true for URLComponents:

let url = URL(string: "s:%F2F'")!
let comps = URLComponents(url: url, resolvingAgainstBaseURL: true)!
print(comps.string) // "s:%F2F'"
print(comps.path)   // ""

@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

1 participant