Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid trailing underscore #31

Merged
merged 2 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
jetersen marked this conversation as resolved.
Show resolved Hide resolved
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)));
}
}
}