Repository navigation
Conversation
cleanAttributes() skipped every attribute without '=', and the tag parser dropped valueless words before a '/' or before another attribute, so '<input checked>' became '<input />' and '<details open>' lost its state even with the attribute allowlisted. Pass those words on as attributes and emit allowed ones as name="". This relies on the attribute-name check, which was dead code: the pattern '/[a-z]*$/i' matches every string. Use '/^[a-z][a-z0-9-]*$/i', mirroring the tag-name check, so names such as '3bb' stay removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Hackwar
force-pushed
the
4.x-boolean-attributes
branch
from
November 12, 2026 23:39
a44be56 to
a81831e
Compare
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.
Summary of Changes
Two related problems in the attribute handling of
InputFilter, fixed together because the first one depends on the second:cleanAttributes()skipped every attribute without=, and the tag parser incleanTags()threw away valueless words that came before a/or before another attribute. So<input checked>became<input />,<details open>became<details>, and forms anddetailselements lost their state.The parser now passes those words on as attributes (unless an unquoted
= valuefollows, which stays dropped as before),cleanAttributes()splits off valueless names that arrive in front of another attribute (checked type="checkbox"), and an allowed attribute without a value is emitted asname="". The usual allow/block lists and theon*and blocked-attribute checks apply unchanged.!preg_match('/[a-z]*$/i', $name)is never true, because the pattern matches the empty string at the end of any input; names of digits or hyphens were only removed incidentally (e.g. because they had no value). It now uses/^[a-z][a-z0-9-]*$/i, mirroring the tag-name check, so<br 3bb />keeps losing3bbonce valueless attributes are kept, and<b 123="x">or<b -x="x">lose them too.data-*attributes are unaffected.Behaviour change in 4.x: with a blocklist configuration (
ONLY_BLOCK_DEFINED_ATTRIBUTES) valueless attributes such asdisabled,ismaporautofocusnow survive asdisabled=""; with an allowlist only when they are listed. The changed expectations in the existing data providers are exactly these cases (Attribute without =,class with no =,disabled_no_equals_*,forward_slash:<textarea autofocus /onfocus=alert(1)>now gives<textarea autofocus="" />— theonfocushandler is still removed). Attribute names that are not ASCII letters/digits/hyphens (e.g. non-Latin names) are now removed.Testing Instructions
New tests:
testCleanKeepsAllowedAttributesWithoutValue()(single, before/after a valued attribute, several, before/,details open, not allowed,on*) andtestCleanRemovesInvalidAttributeNames(). Before the change 22 tests fail (12 new, 10 updated expectations); after itvendor/bin/phpunitpasses.Documentation Changes Required
docs/overview.md: new paragraph on attribute names and valueless attributes in "Filtering HTML"; the bullet saying valueless attributes are always dropped is removed.Related to #104 (both edit the bullet list in "A caution about the HTML filter" in
docs/overview.md; expect a small conflict there).🤖 Generated with Claude Code