Skip to content
Permalink
Browse files
vcs: better regex for real names
Reviewed-by: rwestberg
  • Loading branch information
edvbld committed Sep 11, 2020
1 parent b59316d commit 5c7b36ec7cbfec5ed71f35c29ecc14e2b87fac25
Showing 3 changed files with 22 additions and 3 deletions.
@@ -115,9 +115,10 @@ public CommitMessage parse(List<String> lines) {
while (i < lines.size() && lines.get(i).equals("")) {
i++;

if (matcher(CO_AUTHOR_PATTERN, lines, i) != null ||
matcher(REVIEWED_BY_PATTERN, lines, i) != null) {
if (lines.get(i).startsWith("Co-authored-by:") ||
lines.get(i).startsWith("Reviewed-by:")) {
// "trailers" section

while ((m = matcher(CO_AUTHOR_PATTERN, lines, i)) != null) {
for (var author : m.group(1).split(", ")) {
coAuthors.add(Author.fromString(author));
@@ -27,7 +27,7 @@
public class CommitMessageSyntax {
private static final String OPENJDK_USERNAME_REGEX = "[-.a-z0-9]+";
public static final String EMAIL_ADDR_REGEX = "[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]+";
public static final String REAL_NAME_REGEX = "[-_a-zA-Z0-9][-_ a-zA-Z0-9'.]+";
public static final String REAL_NAME_REGEX = "[^<>@]+";
private static final String REAL_NAME_AND_EMAIL_ATTR_REGEX = REAL_NAME_REGEX + " +<" + EMAIL_ADDR_REGEX + ">";
private static final String ATTR_REGEX = "(?:(?:" + EMAIL_ADDR_REGEX + ")|(?:" + REAL_NAME_AND_EMAIL_ATTR_REGEX + "))";

@@ -224,4 +224,22 @@ void parseVersion1WithUknownTrailer() {
assertEquals(List.of(), message.summaries());
assertEquals(List.of("Unknown-trailer: bar"), message.additional());
}

@Test
void internationalCoAuthors() {
var text = List.of("01234567: An issue",
"",
"Co-authored-by: Föö Bår <foo@bar.com>",
"Co-authored-by: Bår Bäz <bar@baz.com>",
"Reviewed-by: ab, cd, ef");
var message = CommitMessageParsers.v1.parse(text);

assertEquals("01234567: An issue", message.title());
assertEquals(List.of(new Issue("01234567", "An issue")), message.issues());
assertEquals(List.of("ab", "cd", "ef"), message.reviewers());
assertEquals(List.of(new Author("Föö Bår", "foo@bar.com"), new Author("Bår Bäz", "bar@baz.com")),
message.contributors());
assertEquals(List.of(), message.summaries());
assertEquals(List.of(), message.additional());
}
}

1 comment on commit 5c7b36e

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 5c7b36e Sep 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.