Skip to content

Commit

Permalink
avoid trailing underscore
Browse files Browse the repository at this point in the history
as it is not considered a canonical release
  • Loading branch information
jetersen committed Jul 19, 2022
1 parent 5e41c4d commit cddbe3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.AbstractMavenLifecycleParticipant;
import org.apache.maven.MavenExecutionException;
import org.apache.maven.execution.MavenSession;
Expand Down Expand Up @@ -173,7 +174,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 cddbe3b

Please sign in to comment.