Classify HTML bogus comments as comment tokens

Offen
#2,156 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
66/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
java, perl
Bereich
compilers

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.
Vorherrschende Sprache
Perl
Sterne
67
Forks
8
Ø Merge
5 Std. 12 Min.
Gemergte PRs (30 T.)
131

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus fglock/PerlOnJava

Alle Issues in fglock/PerlOnJava

Ähnliche Issues

Weitere Issues zu Perl

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.