fix: serialize attributes through quoteAttribute in removeWhitespace#310
Merged
taoqf merged 1 commit intoJun 29, 2026
Merged
Conversation
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.
removeWhitespace()rebuildsrawAttrsto drop the whitespace between attributes, but it serializes each value withJSON.stringify(val)instead of going throughquoteAttribute, the helper the other write paths use. That leaves it with the two bugs the helper already handles, soremoveWhitespace()corrupts attribute values:<a data-x="C:\Users\me">becomes<a data-x="C:\\Users\\me">and no longer round-trips. This is the same problem fixed for the setter paths in quoteAttribute corrupts attribute values containing '\\' / '\t' / '\n' — round-trip parse(el.toString()) lossy #306 and fix: preserve consecutive backslashes in attribute values #309 (JSON.stringifydoubling backslashes), butremoveWhitespacekept the old serialization.nullvalue.<input disabled required>becomes<input disabled=null required=null>, becauseJSON.stringify(null)is the string"null".setAttribute/removeAttributealready guard this withif (val === 'null' || val === '""') return name.The fix routes the value through
quoteAttributeand applies the same valueless-attribute guard the three other serialization sites (setAttribute,removeAttribute,setAttributes) already use, so all four paths agree.I added two regression tests under
#removeWhitespace(). Without the change they fail with the corrupted output above; with it the suite passes.