Skip to content

Commit

Permalink
Update HTML comment scanning
Browse files Browse the repository at this point in the history
Looks like commonmark.js has a bug in its handling:
commonmark/commonmark.js#285
  • Loading branch information
robinst committed Mar 2, 2024
1 parent 058e2f0 commit 203eeb2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ private static boolean tryProcessingInstruction(Scanner scanner) {
}

private static boolean tryComment(Scanner scanner) {
// spec: An HTML comment consists of <!-- + text + -->, where text does not start with > or ->, does not end
// with -, and does not contain --. (See the HTML5 spec.)
// spec: An [HTML comment](@) consists of `<!-->`, `<!--->`, or `<!--`, a string of
// characters not including the string `-->`, and `-->` (see the
// [HTML spec](https://html.spec.whatwg.org/multipage/parsing.html#markup-declaration-open-state)).

// Skip first `-`
scanner.next();
Expand All @@ -152,12 +153,12 @@ private static boolean tryComment(Scanner scanner) {
}

if (scanner.next('>') || scanner.next("->")) {
return false;
return true;
}

while (scanner.find('-') >= 0) {
if (scanner.next("--")) {
return scanner.next('>');
if (scanner.next("-->")) {
return true;
} else {
scanner.next();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ public class HtmlInlineParserTest extends CoreRenderingTestCase {
public void comment() {
assertRendering("inline <!---->", "<p>inline <!----></p>\n");
assertRendering("inline <!-- -> -->", "<p>inline <!-- -> --></p>\n");
assertRendering("inline <!--->-->", "<p>inline &lt;!---&gt;--&gt;</p>\n");
assertRendering("inline <!-- -- -->", "<p>inline <!-- -- --></p>\n");
assertRendering("inline <!-- --->", "<p>inline <!-- ---></p>\n");
assertRendering("inline <!-- ---->", "<p>inline <!-- ----></p>\n");
assertRendering("inline <!-->-->", "<p>inline <!-->--&gt;</p>\n");
assertRendering("inline <!--->-->", "<p>inline <!--->--&gt;</p>\n");
}

@Test
Expand Down

0 comments on commit 203eeb2

Please sign in to comment.