diff --git a/java/com/google/copybara/rust/RustCratesIoVersionList.java b/java/com/google/copybara/rust/RustCratesIoVersionList.java index 46efeeb32..bc5d19e84 100644 --- a/java/com/google/copybara/rust/RustCratesIoVersionList.java +++ b/java/com/google/copybara/rust/RustCratesIoVersionList.java @@ -18,6 +18,7 @@ import static com.google.common.collect.ImmutableSet.toImmutableSet; +import com.google.common.base.Ascii; import com.google.common.collect.ImmutableSet; import com.google.copybara.exception.RepoException; import com.google.copybara.exception.ValidationException; @@ -63,19 +64,21 @@ ImmutableSet getVersionList() throws RepoException { String url = CRATES_IO_INDEX_URL; int nameLength = crateName.length(); + String indexCrateName = Ascii.toLowerCase(crateName); if (nameLength <= 2) { // If the crate name's length is less than or equal to 2, then the version info is located at // // - url += String.format("/%d/%s", nameLength, crateName); + url += String.format("/%d/%s", nameLength, indexCrateName); } else if (nameLength == 3) { // If the crate name's length is equal to 3, then the version info is at: // /3// - url += String.format("/%d/%c/%s", nameLength, crateName.charAt(0), crateName); + url += String.format("/%d/%c/%s", nameLength, indexCrateName.charAt(0), indexCrateName); } else { url += String.format( - "/%s/%s/%s", crateName.substring(0, 2), crateName.substring(2, 4), crateName); + "/%s/%s/%s", + indexCrateName.substring(0, 2), indexCrateName.substring(2, 4), indexCrateName); } BufferedReader reader = new BufferedReader(new StringReader(executeHTTPQuery(url))); diff --git a/javatests/com/google/copybara/rust/RustCratesIoVersionListTest.java b/javatests/com/google/copybara/rust/RustCratesIoVersionListTest.java index f2737b712..61baa1c14 100644 --- a/javatests/com/google/copybara/rust/RustCratesIoVersionListTest.java +++ b/javatests/com/google/copybara/rust/RustCratesIoVersionListTest.java @@ -197,4 +197,23 @@ public void testRustCrateIoVersionList_withFeatures() throws Exception { assertThat(resultFeatures).containsKey("example-feature"); assertThat(resultFeatures.get("example-feature").get(0)).isEqualTo("feature2"); } + + @Test + public void testRustCrateIoVersionList_cratesWithUpperCaseName() throws Exception { + JsonObject v1 = new JsonObject(); + v1.add("name", new JsonPrimitive("Example")); + v1.add("vers", new JsonPrimitive("0.1.0")); + String content = + ImmutableList.of(v1).stream().map(JsonElement::toString).collect(Collectors.joining("\n")); + + setUpMockTransportForSkylarkExecutor( + ImmutableMap.of( + "https://raw.githubusercontent.com/rust-lang/crates.io-index/master/ex/am/example", + content)); + // The crate name starts with an uppercase letter, but when we look up in the index, we use the + // lowercase spelling. + VersionList versionList = + skylark.eval("version_list", "version_list = rust.crates_io_version_list(crate='Example')"); + assertThat(versionList.list()).containsExactlyElementsIn(ImmutableList.of("0.1.0")); + } }