Skip to content

Replace invalid characters in attribute names - #762

Merged
tagliala merged 1 commit into
masterfrom
fix/attribute-names-master
Dec 3, 2026
Merged

tagliala merged 1 commit into
masterfrom
fix/attribute-names-master

Conversation

@tagliala

@tagliala tagliala commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Attribute names were HTML-escaped, but characters that the HTML syntax does not allow in an attribute name (controls, space, ", ', /, = and >) were kept, so a name containing them did not render as a single attribute.

Each of these characters is now replaced with _, in top-level and nested attribute names. Names that are already valid render unchanged, including @click, :class, [value], (click) and #ref. The same change is going into 2.2.2.

Verification

The fuzzing and Active Admin runs used the change applied to v2.2.1 (the 2.2.2 code). The library change is the same on this branch.

Specs: 185 examples, 0 failures.

Fuzzing of attribute names, 100,000 random names, top-level and nested, comparing v2.2.1 with the change:

  • 50,000 cases with only allowed characters: output is identical.
  • Every parsed UTF-8 result (95,449 cases) is one element with the expected number of attributes, according to Nokogiri's HTML5 parser.
  • Names that raised before still raise the same exception class, and no name raises that did not before.

Fuzzing of whole trees, 20,000 random trees with plain values and 20,000 with unusual ones (invalid or mixed encodings, custom to_s), using allowed attribute names: no difference from v2.2.1 in output, encoding, html_safe? or exception class. About a third of the trees render; the others raise the same way in both versions.

Active Admin (5cda8009d, Ruby 3.3.12, Rails 8.1):

  • RSpec: 1602 examples, 0 failures.
  • Cucumber, default profile: 262 scenarios passed. The filesystem-changes and class-reloading profiles also pass.
  • Logging every attribute name rendered during these runs showed no name changed by this fix.

The fuzzing was run on Ruby 4.0.9 only.

🤖 Generated with Claude Code

Attribute names were HTML-escaped, but characters that the HTML
syntax does not allow in an attribute name (controls, space, ", ',
/, = and >) were kept, so a name containing them did not render as
a single attribute.

Replace each of these characters with "_" in top-level and nested
attribute names. Names that are already valid render unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Dec 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (7ba87c0) to head (5b12c26).

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #762   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        17           
  Lines          459       465    +6     
=========================================
+ Hits           459       465    +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tagliala
tagliala merged commit df6a0f2 into master Dec 3, 2026
18 checks passed
@tagliala
tagliala deleted the fix/attribute-names-master branch December 3, 2026 09:28
@tagliala tagliala mentioned this pull request Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant