Skip to content

Commit

Permalink
Merge pull request #31 from jetersen-cloud/fix/trailingSanitize
Browse files Browse the repository at this point in the history
avoid trailing underscore
  • Loading branch information
jglick committed Jul 19, 2022
2 parents 5e41c4d + d98aac7 commit eb390da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void afterSessionStart(MavenSession session) throws MavenExecutionExcepti
}

static String sanitize(String hash) {
return hash.replaceAll("[ab]", "$0_");
return hash.replaceAll("[ab]", "$0_").replaceAll("_$", "");
}

private static String summarize(RevCommit c) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class MainTest {
// Nonstandard ones in Dependabot? https://github.com/dependabot/dependabot-core/blob/f146743aa400c7913b5e953e1b93c8b40345aaf4/maven/lib/dependabot/maven/version.rb#L24-L25
"pr", "dev",
};

@Test public void alphaBeta() {
String hash = "852b473a2b8c";
String sanitized = Main.sanitize(hash);
Expand All @@ -52,4 +53,13 @@ public class MainTest {
}
}

@Test public void alphaBetaTrailing() {
String hash = "852b473a2bcb";
String sanitized = Main.sanitize(hash);
assertThat(hash + " has been sanitized to the expected format", sanitized, is("852b_473a_2b_cb"));
String canonical = new ComparableVersion(sanitized).getCanonical();
for (String prerelease : PRERELEASE) {
assertThat(sanitized + " treated as a prerelease", canonical, not(containsString(prerelease)));
}
}
}

0 comments on commit eb390da

Please sign in to comment.