fix: stop encoding underscores in HTML attribute values#26
Merged
Conversation
Helper::buildHtmlAttributes() serializes widget attributes via
htmlentities($v, ENT_QUOTES | ENT_HTML5, 'UTF-8'). The HTML5 named-entity
table encodes "_" as "_" (and " " as " ", etc.), so a radio
widget rendered with name="account_category" ends up in the DOM as the
literal string "account_category" — breaking [name="..."] selectors
and form submission for any column whose name contains an underscore.
Repro: $form->radio('account_category', '...') — source HTML shows
name="account_category"
parsed DOM attribute value:
account_category (literal, not "account_category")
Fix: use ENT_QUOTES only — same character set htmlspecialchars uses,
which is the correct rule for serializing HTML attribute values.
Affected widgets: Radio, Checkbox, Switch, and any custom widget that
uses formatHtmlAttributes(). Standard form fields rendered via Blade
{{ }} are unaffected.
PrintNow
approved these changes
May 25, 2026
Owner
|
@chipin 👍🏻 Thanks for the contribution! I'll merge it shortly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Helper::buildHtmlAttributes()serializes widget attributes via:The HTML5 named-entity table encodes
_as_,as , and many other ordinary characters that should not appear as entities inside an attribute value. When the resulting attribute is later combined with another layer of escaping (e.g.&→&), the source HTML for a Radio widget ends up like:…which the browser parses into a DOM attribute whose literal value is
account_category(with literal&and the charslowbar;), notaccount_category. That breaks:document.querySelector('[name="account_category"]')— finds 0 elements$('[name="account_category"]')— finds 0 elementsaccount_category=...instead ofaccount_category=..., so the controller never sees the value under its expected keyRepro
Inspect the rendered HTML — every radio
<input>hasname="account&lowbar;category".Affected widgets
Anything that goes through
Helper::buildHtmlAttributes()viaformatHtmlAttributes():Radio, Checkbox, Switch, and any custom
Widgetsubclass. Standard form fields rendered through Blade{{ }}are not affected.Fix
Switch the entity flag set to
ENT_QUOTESonly — the same character sethtmlspecialchars()uses, which is the correct rule for serializing HTML attribute values (& < > " 'only):Before:
After:
Notes
& < > " ', behaviour is identical tohtmlspecialchars($v, ENT_QUOTES).