Skip to content

Commit 89ef023

Browse files
committed
Improve lexing of HTML comments
1 parent 771c57f commit 89ef023

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

ext/erbx/test/lexer/tags_test.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,5 +525,50 @@ class TagsTest < Minitest::Spec
525525

526526
assert_equal expected, result.array.items.map(&:type)
527527
end
528+
529+
test "HTML comment followed by html tag" do
530+
result = ERBX.lex(%(<!--Hello World--><h1>Hello</h1>))
531+
532+
expected = %w[
533+
TOKEN_HTML_COMMENT_START
534+
TOKEN_HTML_COMMENT_CONTENT
535+
TOKEN_HTML_COMMENT_END
536+
TOKEN_HTML_TAG_START
537+
TOKEN_HTML_TAG_NAME
538+
TOKEN_HTML_TAG_END
539+
TOKEN_TEXT_CONTENT
540+
TOKEN_HTML_CLOSE_TAG_START
541+
TOKEN_HTML_TAG_NAME
542+
TOKEN_HTML_TAG_END
543+
TOKEN_EOF
544+
]
545+
546+
assert_equal expected, result.array.items.map(&:type)
547+
end
548+
549+
xtest "HTML comment followed by html tag with nested comment" do
550+
result = ERBX.lex(%(
551+
<!--Hello World-->
552+
<h1><!-- Hello World --></h1>
553+
))
554+
555+
expected = %w[
556+
TOKEN_HTML_COMMENT_START
557+
TOKEN_HTML_COMMENT_CONTENT
558+
TOKEN_HTML_COMMENT_END
559+
TOKEN_HTML_TAG_START
560+
TOKEN_HTML_TAG_NAME
561+
TOKEN_HTML_TAG_END
562+
TOKEN_HTML_COMMENT_START
563+
TOKEN_HTML_COMMENT_CONTENT
564+
TOKEN_HTML_COMMENT_END
565+
TOKEN_HTML_CLOSE_TAG_START
566+
TOKEN_HTML_TAG_NAME
567+
TOKEN_HTML_TAG_END
568+
TOKEN_EOF
569+
]
570+
571+
assert_equal expected, result.array.items.map(&:type)
572+
end
528573
end
529574
end

src/lexer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ token_T* lexer_handle_html_comment_close_state(lexer_T* lexer) {
434434
lexer_advance(lexer);
435435
lexer_advance(lexer);
436436
lexer_advance(lexer);
437+
lexer->state = STATE_DATA;
437438
return token_init("-->", TOKEN_HTML_COMMENT_END, lexer);
438439
}
439440

0 commit comments

Comments
 (0)