1+ require 'test/unit'
2+ require 'coderay'
3+
4+ class HtmlCommentFilteringTest < Test ::Unit ::TestCase
5+
6+ def test_html_comment_filtering_consistency
7+ # Test case based on issue #262
8+ # Comments with extra characters after --> should be handled consistently
9+
10+ # Normal comment ending with -->
11+ html_normal_comment = <<-HTML
12+ < script >
13+ <!-- This is a normal comment -->
14+ alert ( 'test' ) ;
15+ </ script >
16+ HTML
17+
18+ # Comment ending with -->!> (extra characters after comment end)
19+ html_comment_with_extra = <<-HTML
20+ < script >
21+ <!-- This is a comment -->!>
22+ alert ( 'test' ) ;
23+ </ script >
24+ HTML
25+
26+ tokens_normal = CodeRay . scan ( html_normal_comment , :html )
27+ tokens_extra = CodeRay . scan ( html_comment_with_extra , :html )
28+
29+ html_normal = tokens_normal . html
30+ html_extra = tokens_extra . html
31+
32+ # Both comments should be properly tokenized without error tokens
33+ # The normal comment should end with -->
34+ assert html_normal . include? ( '--></span>' ) , "Normal comment should end with -->"
35+ assert !html_normal . include? ( 'error' ) , "Normal comment should not contain error tokens"
36+
37+ # The comment with extra chars should end with -->!> and not have separate error tokens
38+ assert html_extra . include? ( '-->!></span>' ) , "Comment with extra chars should end with -->!>"
39+ assert !html_extra . include? ( 'error' ) , "Comment with extra chars should not contain error tokens"
40+
41+ # Both should have the same basic structure: comment opening, inline content, comment closing
42+ assert html_normal . include? ( '<span class="comment"> <!--</span>' ) , "Normal comment should have proper opening"
43+ assert html_extra . include? ( '<span class="comment"> <!--</span>' ) , "Extra comment should have proper opening"
44+
45+ assert html_normal . include? ( '<span class="inline">' ) , "Normal comment should have inline content"
46+ assert html_extra . include? ( '<span class="inline">' ) , "Extra comment should have inline content"
47+ end
48+
49+ end
0 commit comments