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

Avoid merging URLs in HttpUtils #14922

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ private static URL mergeUrls(URI preferred, URL original) throws IOException {
// scheme of their redirect URLs.
if (preferred.getHost() != null
&& preferred.getScheme() != null
&& (preferred.getUserInfo() != null || original.getUserInfo() == null)
&& (preferred.getFragment() != null || original.getRef() == null)) {
// In this case we obviously do not inherit anything from the original URL, as all inheritable
// fields are either set explicitly or not present in the original either. Therefore, it is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,14 @@ public void getLocation_preservesQuotingIfNotInheriting() throws Exception {
when(connection.getHeaderField("Location")).thenReturn(redirect);
assertThat(HttpUtils.getLocation(connection)).isEqualTo(URI.create(redirect).toURL());
}

@Test
public void getLocation_preservesQuotingWithUserIfNotInheriting() throws Exception {
String redirect =
"http://redirected.example.org/foo?"
+ "response-content-disposition=attachment%3Bfilename%3D%22bar.tar.gz%22";
when(connection.getURL()).thenReturn(new URL("http://a:b@original.example.org"));
when(connection.getHeaderField("Location")).thenReturn(redirect);
assertThat(HttpUtils.getLocation(connection)).isEqualTo(URI.create(redirect).toURL());
}
}