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

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

Merged
merged 2 commits into from
Apr 15, 2020

Conversation

iainsmith
Copy link
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

Can one of the admins verify this patch?

3 similar comments
@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@swift-server-bot
Copy link

Can one of the admins verify this patch?

@Lukasa
Copy link
Collaborator

Lukasa commented Apr 14, 2020

@swift-server-bot test this please

@Lukasa
Copy link
Collaborator

Lukasa commented Apr 14, 2020

Flaky test: #175.

@Lukasa
Copy link
Collaborator

Lukasa commented Apr 14, 2020

@swift-server-bot test this please

1 similar comment
@Lukasa
Copy link
Collaborator

Lukasa commented Apr 14, 2020

@swift-server-bot test this please

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

@Lukasa Lukasa left a comment

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
Collaborator

@swift-server-bot test this please

@iainsmith
Copy link
Contributor Author

iainsmith commented Apr 14, 2020

@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 != "/" {
Copy link
Contributor Author

@iainsmith iainsmith Apr 14, 2020

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
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
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