From 3bfe3d937163aed2962d9de3e657ec0ae8716beb Mon Sep 17 00:00:00 2001 From: Kurt Alfred Kluever Date: Mon, 6 Jul 2026 17:57:58 -0700 Subject: [PATCH] Add[] CommonMark spec permits ordered list markers using either a period (`.`) or a right parenthesis (`)`). When a Javadoc comment starting with `///` contains an ordered list item formatted as `1) foo` or `1)the previous node`, CommonMark's parser identifies it as a `ListItem` node. However, `MarkdownPositions.TokenVisitor.visitListItem` currently expects all ordered list items to match `LIST_ITEM_START_PATTERN`, which strictly checks for digits followed by `.` and a space. When a parenthesis list marker is encountered, `lookingAt()` returns `false`, and `verify()` throws a `VerifyException` that escapes the formatter. Per[] PiperOrigin-RevId: 943587323 --- .../java/JavadocFormattingTest.java | 17 +++++++++++++++++ .../java/javadoc/MarkdownPositionsTest.java | 15 +++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java b/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java index 0a9c388a1..24b762d69 100644 --- a/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java +++ b/core/src/test/java/com/google/googlejavaformat/java/JavadocFormattingTest.java @@ -18,7 +18,9 @@ import static com.google.common.truth.Truth.assertWithMessage; import static com.google.common.truth.TruthJUnit.assume; import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.Assert.assertThrows; +import com.google.common.base.VerifyException; import com.google.common.io.ByteStreams; import org.junit.Test; import org.junit.runner.RunWith; @@ -2122,6 +2124,21 @@ public void markdownLongCommentOnPackageDeclaration() { doFormatTest(input, expected); } + // TODO: b/346668798 - This should not throw an exception. + // CommonMark allows ')' as an ordered list marker (e.g. '1) foo'), but MarkdownPositions + // only expects '.' in LIST_ITEM_START_PATTERN, throwing a VerifyException. + @Test + public void markdownOrderedListWithParenthesis() { + assume().that(MARKDOWN_JAVADOC_SUPPORTED).isTrue(); + String input = + """ + /// 1) first item + /// 2) second item + class Test {} + """; + assertThrows(VerifyException.class, () -> formatter.formatSource(input)); + } + // TODO: b/346668798 - Test the following Markdown constructs, and make the tests work as needed. // We can assume that the CommonMark parser correctly handles Markdown, so the question is whether // they are subsequently mishandled by our formatting logic. So for example the CommonMark parser diff --git a/core/src/test/java/com/google/googlejavaformat/java/javadoc/MarkdownPositionsTest.java b/core/src/test/java/com/google/googlejavaformat/java/javadoc/MarkdownPositionsTest.java index e1b5fcd12..8bd260b85 100644 --- a/core/src/test/java/com/google/googlejavaformat/java/javadoc/MarkdownPositionsTest.java +++ b/core/src/test/java/com/google/googlejavaformat/java/javadoc/MarkdownPositionsTest.java @@ -15,7 +15,9 @@ import static com.google.common.collect.ImmutableListMultimap.flatteningToImmutableListMultimap; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertThrows; +import com.google.common.base.VerifyException; import com.google.common.collect.ImmutableListMultimap; import com.google.googlejavaformat.java.javadoc.Token.HeaderCloseTag; import com.google.googlejavaformat.java.javadoc.Token.HeaderOpenTag; @@ -65,6 +67,19 @@ public void list() { assertThat(map).isEqualTo(expected); } + // TODO: b/346668798 - This should not throw an exception. + // CommonMark allows ')' as an ordered list marker (e.g. '1) foo'), but MarkdownPositions + // only expects '.' in LIST_ITEM_START_PATTERN, throwing a VerifyException. + @Test + public void listWithParenthesis() { + String text = +""" +1) foo +2) bar +"""; + assertThrows(VerifyException.class, () -> MarkdownPositions.parse(text)); + } + @Test public void heading() { String text =