Classify HTML bogus comments as comment tokens

Đang mở
#2,156 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
66/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java, perl
Lĩnh vực
compilers

Hướng nghiên cứu

Start in HTMLParser.parseHtml, at the branch that handles < ! ... > and currently only recognises [ marked sections and -- comments; everything else falls through to declaration token D. Read how the C token is emitted for <!-- --> and mirror that path for the bogus-comment form, then confirm via HTML::TokeParser that <! comment !> yields ['C', ...]. Reproduce first with the ignore_comments snippet, then add token-classification and diff regression tests and run t/text_diff.t on both the JVM and interpreter backends.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

area:cpan-port area:parser area:runtime bug

Summary

The HTML::Parser implementation classifies the HTML bogus comment <! comment !> as a declaration. System Perl classifies the same token as a comment. This causes callers that ignore comments to retain the token and report a false HTML difference.

Reproduction

With HTML-Differences 0.01:

use HTML::Differences qw(html_text_diff);

my $left  = '<p>x</p>';
my $right = '<p>x</p><! comment !>';
print html_text_diff($left, $right, ignore_comments => 1);

Expected: an empty string, because the only difference is a comment and ignore_comments is enabled.

Actual on PerlOnJava: the diff includes <! comment !> as an added line.

A direct token check isolates the discrepancy: HTML::TokeParser under system Perl emits ['C', '<! comment !>']; PerlOnJava emits ['D', '<! comment !>']. HTML::Differences::diffable_html dispatches C tokens to its comment handler, which drops them when ignore_comments is true. A D token goes to the declaration handler and is kept, so the option is bypassed.

Evidence

  • CPAN distribution: HTML-Differences 0.01; tester run 20261120-195805-13340.
  • Upstream system-Perl oracle: all 14 tests passed, including t/text_diff.t.
  • PerlOnJava: t/text_diff.t fails its no diff found when comment differs and told to ignore comments assertion.
  • The same failure reproduces on JVM and interpreter backends.
  • Runtime reports Perl 5.44.1, Java 24.0.2, macOS (Darwin 25.6). The tester's system-Perl oracle used Perl 5.42.2.
  • The module is pure Perl; no native dependency or external service is involved.

Root cause

In HTMLParser.parseHtml, the branch handling <!...> recognizes marked sections beginning with [ and comments beginning with --. Every other form is emitted as a declaration. It does not implement HTML::Parser's bogus-comment handling for <! ... >, which is why <! comment !> receives token type D rather than C.

Acceptance criteria

  1. <! comment !> is emitted as a comment token by HTML::TokeParser, matching system Perl.
  2. The minimal ignore_comments reproducer returns an empty string on JVM and interpreter backends.
  3. Add focused project-owned regression coverage for token classification and ignored-comment diffing, validated against system Perl.
  4. Re-run HTML-Differences 0.01 t/text_diff.t on both PerlOnJava backends.
Ngôn ngữ chính
Perl
Star
67
Fork
8
Merge trung bình
5 giờ 12 phút
Pull request đã merge (30 ngày)
131

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của fglock/PerlOnJava

Tất cả issue của fglock/PerlOnJava

Issue tương tự

Thêm issue về Perl

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.