Skip to content

Commit

Permalink
Properly escape GitHub repository download URL for git_repository w/ …
Browse files Browse the repository at this point in the history
…sha256

Addresses bazelbuild#3661

Closes bazelbuild#3770.

PiperOrigin-RevId: 171797773
  • Loading branch information
akirabaruah authored and hlopko committed Oct 11, 2017
1 parent 8e04f24 commit 0a63dad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ private static Optional<Exception> downloadRepositoryAsHttpArchive(
String repositoryName = matcher.group(2);
String downloadUrl =
"https://github.com/"
+ UrlEscapers.urlPathSegmentEscaper().escape(
user + "/" + repositoryName + "/archive/" + descriptor.ref + ".tar.gz");
+ UrlEscapers.urlFragmentEscaper()
.escape(user + "/" + repositoryName + "/archive/" + descriptor.ref + ".tar.gz");
try {
FileSystemUtils.createDirectoryAndParents(descriptor.directory);
Path tgz = downloader.download(ImmutableList.of(new URL(downloadUrl)), uncheckedSha256,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import static org.mockito.Matchers.anyListOf;
import static org.mockito.Matchers.anyMapOf;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
import com.google.devtools.build.lib.bazel.repository.cache.RepositoryCache;
Expand Down Expand Up @@ -82,6 +84,14 @@ public void testSha256TarballOkay() throws Exception {

HttpDownloadValue value = GitCloner.clone(
rule, outputDirectory, eventHandler, clientEnvironment, downloader);
verify(downloader)
.download(
eq(ImmutableList.of(new URL("https://github.com/foo/bar/archive/1.2.3.tar.gz"))),
any(String.class),
eq(Optional.of("tar.gz")),
eq(outputDirectory),
any(ExtendedEventHandler.class),
anyMapOf(String.class, String.class));
assertThat(value).isNotNull();
assertThat(value.getPath()).isEqualTo(outputDirectory);
}
Expand Down

0 comments on commit 0a63dad

Please sign in to comment.