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-11341] Foundation.URL meddles with trailing slashes #3392

Open
swift-ci opened this issue Aug 21, 2019 · 3 comments
Open

[SR-11341] Foundation.URL meddles with trailing slashes #3392

swift-ci opened this issue Aug 21, 2019 · 3 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-11341
Radar None
Original Reporter pkese (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 3605e665922c3e154e7323c7a03f72e8

Issue Description:

The following test fails with path missing trailing slash

let url = URL(string: "https://someserver.com:8888/some/path/?foo=bar")!
XCTAssertEqual(url.path, "/some/path/") 
XCTAssertEqual failed: ("/some/path") is not equal to ("/some/path/")

In case someone decides to defend the above issue as 'correct', then please take into account also the following:

let url = URL(string: "https://someserver.com:8888/some/path//?foo=bar")!
XCTAssertEqual(url.path, "/some/path//") 
XCTAssertEqual failed: ("/some/path/") is not equal to ("/some/path//")
@swift-ci
Copy link
Contributor Author

Comment by Peter Kese (JIRA)

This happened on Linux, btw.

I haven't checked it on Mac.

@spevans
Copy link
Collaborator

spevans commented Oct 7, 2019

.path simply removes the last trailing slash:

print(URL(string: "https://someserver.com:8888/some/path?foo=bar")!.path)
print(URL(string: "https://someserver.com:8888/some/path/?foo=bar")!.path)
print(URL(string: "https://someserver.com:8888/some/path//?foo=bar")!.path)
print(URL(string: "https://someserver.com:8888/some/path///?foo=bar")!.path)

print(URL(fileURLWithPath: "/path/").path)
print(URL(fileURLWithPath: "/path//").path)
print(URL(fileURLWithPath: "/path///").path) 

gives:

/some/path
/some/path
/some/path/
/some/path//
/path
/path/
/path//

The only case this isnt true is if it is the root directory /

print(URL(fileURLWithPath: "/").path)
print(URL(fileURLWithPath: "//").path)
print(URL(fileURLWithPath: "///").path)
/
/
//

This is consistent between macOS and Linux versions.

@swift-ci
Copy link
Contributor Author

swift-ci commented Oct 7, 2019

Comment by Peter Kese (JIRA)

Indeed it does.

The REST API server that my code is calling is expecting these slashes at the ends of paths and is thus returning me HTTP 404s.

@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