Skip to content

Enable clients to call URLs that include %2F as an escaped backslash#201

Merged
weissi merged 2 commits into
swift-server:masterfrom
iainsmith:master
Apr 15, 2020
Merged

Enable clients to call URLs that include %2F as an escaped backslash#201
weissi merged 2 commits into
swift-server:masterfrom
iainsmith:master

Conversation

@iainsmith

Copy link
Copy Markdown
Contributor

Hi 👋, thanks for all the great work on this project.

I have a package that calls the Travis API, which uses %2F as part of the URL path segment. This PR adds a test case & migrates to URLComponents(url: self, resolvingAgainstBaseURL: false)?.percentEncodedPath which covers that use case.

I also updated the test server to switch on the percentEncodedPath so it's easier
to understand the desired behaviour. I've tested this locally on 10.15.4 but not on Ubuntu.

Previously `percentEncodedPath` was using `path.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)`
which converts %2F to a literal '/'. This prevented users fetching URLs like https://api.travis-ci.org/repo/github/rails%2Frails
which use %2F as part of a path segment.

Migrating to `URLComponents(url: self, resolvingAgainstBaseURL: false)?.percentEncodedPath` has the desired behaviour
for the couple of test cases that exist.

Updated the test server to switch on the `percentEncodedPath` so it's easier
to understand the desired behaviour.
@swift-server-bot

Copy link
Copy Markdown

Can one of the admins verify this patch?

3 similar comments
@swift-server-bot

Copy link
Copy Markdown

Can one of the admins verify this patch?

@swift-server-bot

Copy link
Copy Markdown

Can one of the admins verify this patch?

@swift-server-bot

Copy link
Copy Markdown

Can one of the admins verify this patch?

@Lukasa

Lukasa commented Apr 14, 2020

Copy link
Copy Markdown
Collaborator

@swift-server-bot test this please

@Lukasa

Lukasa commented Apr 14, 2020

Copy link
Copy Markdown
Collaborator

Flaky test: #175.

@Lukasa

Lukasa commented Apr 14, 2020

Copy link
Copy Markdown
Collaborator

@swift-server-bot test this please

1 similar comment
@Lukasa

Lukasa commented Apr 14, 2020

Copy link
Copy Markdown
Collaborator

@swift-server-bot test this please

@weissi weissi requested review from Lukasa and artemredkin and removed request for Lukasa April 14, 2020 10:14

@Lukasa Lukasa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable to me, assuming we can get the dang tests to pass.

@artemredkin

Copy link
Copy Markdown
Collaborator

@swift-server-bot test this please

@iainsmith

iainsmith commented Apr 14, 2020

Copy link
Copy Markdown
Contributor Author

@Lukasa @artemredkin, I just rechecked this locally (disabling the flakey test) and I noticed that I'm hitting a few legitimate failures on testRequestURITrailingSlash that I need to fix.

let request6 = try Request(url: "https://someserver.com:8888/some/path/")
XCTAssertEqual(request6.url.uri, "/some/path/") // XCTAssertEqual failed: ("/some/path//") is not equal to ("/some/path/")


var uri: String {
var uri = self.percentEncodedPath
if self.pathHasTrailingSlash, uri != "/" {

@iainsmith iainsmith Apr 14, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it seems this case is handled correctly through the URLComponenets.percentEncodedPath approach. This behaviour looks well tested in testRequestURITrailingSlash which should now be passing (at least on iOS and macOS).

@iainsmith

Copy link
Copy Markdown
Contributor Author

I pushed another commit that removes some redundant code. Would one of you mind re-triggering CI?

Also happy to squash the commits if that is preferred here.

@artemredkin

Copy link
Copy Markdown
Collaborator

@swift-server-bot test this please

@weissi weissi added the 🔨 semver/patch No public API change. label Apr 15, 2020
@weissi weissi merged commit be517e3 into swift-server:master Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants