fix(capture): drop *-prefixed attributes to keep XMLSerializer output well-formed - #445
Merged
tinchox5 merged 1 commit intoJul 3, 2026
Conversation
venkateshwarreddyr
force-pushed
the
fix/star-prefixed-attributes
branch
from
July 1, 2026 04:26
ff70504 to
7a66302
Compare
…put valid HTML attribute names beginning with "*" (e.g. Angular structural directives like *ngIf, *ngFor, or any custom *data-foo) are valid in HTML5 but illegal in XML: "*" is not allowed as a NameStartChar. sanitizeAttributesForXHTML already strips "@" and unknown ":" prefixes because they survive HTML parsing but break XMLSerializer output, leaving the resulting data: URL unparseable and triggering "EncodingError: The source image cannot be decoded" at img.decode() time. "*" was missing from that pass. Add a strip rule in sanitizeAttributesForXHTML alongside the existing "@" / namespace checks. Placed outside the stripFrameworkDirectives opt-out because it is an XML-spec rule, not a framework convention. Fixes zumerlab#446. Adds a regression test covering *ngIf-style Angular directives and arbitrary *custom-attr names.
venkateshwarreddyr
force-pushed
the
fix/star-prefixed-attributes
branch
from
July 1, 2026 04:29
7a66302 to
1e706c8
Compare
Member
|
Thank you @venkateshwarreddyr for this contribution and welcome!! |
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
Fixes #446.
HTML attribute names beginning with
*(e.g. Angular structural directives like*ngIf,*ngFor, or any custom*data-foo) are valid in HTML5 but illegal in XML —*is not aNameStartChar. They survive cloning, get serialized byXMLSerializer.serializeToStringinto<foreignObject>, and the resulting data: URL is malformed.img.decode()then throwsEncodingError: The source image cannot be decoded..Problem
sanitizeAttributesForXHTMLalready strips attribute names that would break the XHTML serializer:@— never valid in XML:prefixes (onlyxml/xlinkallowed)x-*,v-*,:,on:*,bind:*,let:*,class:*)*is anotherNameStartCharviolation but was missing from that pass. Browsers don't enforce XML rules on serialization, so this only blows up downstream atimg.decode(). Any Angular app — or any code that callssetAttribute('*name', …)— hits this.Change
Add a single rule to
sanitizeAttributesForXHTML:Placed outside the
stripFrameworkDirectivesopt-out because it's an XML-spec rule, not a framework convention —*should always be stripped regardless of options.__tests__/snapdom.starAttributes.test.js:*ngIf/*ngFor/*data-custom*-prefixed attributesTest plan
main(EncodingError+*-attrs present in SVG)npx vitest run --browser.headless→ 553 passed, 1 skipped, 0 failednpm run lintcleansnapdom.attributes.test.js,snapdom.invalidXMLChars.test.jspass unchanged