diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpUtils.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpUtils.java index 5853ef3c281c8d..4d7c8ba3be2e67 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpUtils.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpUtils.java @@ -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 diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpUtilsTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpUtilsTest.java index aeac4d978f106b..a93bb344fc8949 100644 --- a/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpUtilsTest.java +++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpUtilsTest.java @@ -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()); + } }