Skip to content

content/hidden-text: a comment before a selector stops a plain hiding rule from applying #684

Closed

Description

@nc9

Summary. content/hidden-text never applies a <style> rule whose selector has a CSS comment before or inside it. parseRules in packages/rules/src/content/hidden-text.ts skips comments while scanning but keeps them in the selector text, so /* Header */ .b is not a bare class selector: the rule is treated as a complex selector and only marks .b as ambiguous. A browser ignores the comment and applies the rule.

Found while fixing #679, on current main and with the #679 branch alike.

Repro (HTTP mode, local fixture):

<style>
.a{color:red}
/* Section */
.b{display:none}
</style>
<p class="b">Sixty or more characters of ordinary visible paragraph text go here, so the rule has something to flag.</p>

Actual: no finding. Chromium (getComputedStyle) hides .b. The same holds for a comment between the selector and { (.b /* x */ {display:none}).

This errs toward no finding, which is the safe direction for this rule, but section comments between rules are ordinary in hand-written stylesheets, so plainly hidden text goes unreported on those pages. Fixing it will change results on ordinary stylesheets (more findings), so it needs a corpus check before it lands.

Acceptance Criteria

  • A bare class or id rule preceded by a comment (/* x */ .b{display:none}) is applied, and the repro produces a hidden-text finding.
  • A comment between the selector and { does not stop the rule from applying.
  • A selector that is still complex once comments are removed (.a /* x */ .b) is still treated as ambiguous.
  • The change is measured on a page corpus before merge, with the number of pages whose findings change reported in the PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3bugrulessize: S

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions