Update svgWhiteList in sanitize.js to include 'font-stretch' for rele…#1081
Merged
Conversation
…vant SVG elements
Reviewer's guide (collapsed on small PRs)Reviewer's GuideExtends the SVG sanitizer whitelist to preserve the Class diagram for updated svgWhiteList_ sanitizer configurationclassDiagram
class SvgSanitizer {
- svgWhiteList_
+ sanitizeSvg(svgInput)
}
class SvgWhiteListEntry_g {
+clip_path
+clip_rule
+fill
+fill_opacity
+fill_rule
+filter
+mask
+opacity
+requiredFeatures
+stroke
+stroke_dasharray
+stroke_dashoffset
+stroke_linecap
+stroke_linejoin
+stroke_miterlimit
+stroke_opacity
+stroke_width
+systemLanguage
+font_family
+font_size
+font_stretch
+font_style
+font_weight
+text_anchor
}
class SvgWhiteListEntry_symbol {
+fill
+fill_opacity
+fill_rule
+filter
+font_family
+font_size
+font_stretch
+font_style
+font_weight
+opacity
+overflow
+preserveAspectRatio
+requiredFeatures
+stroke
+stroke_dasharray
+stroke_dashoffset
+stroke_linecap
+stroke_linejoin
+stroke_miterlimit
+stroke_opacity
+stroke_width
+systemLanguage
+viewBox
+width
+height
}
class SvgWhiteListEntry_text {
+clip_path
+clip_rule
+dominant_baseline
+fill
+fill_opacity
+fill_rule
+filter
+font_family
+font_size
+font_stretch
+font_style
+font_weight
+mask
+opacity
+requiredFeatures
+stroke
+stroke_dasharray
+stroke_dashoffset
+stroke_linecap
+stroke_linejoin
+stroke_miterlimit
+stroke_opacity
+stroke_width
+systemLanguage
+text_anchor
+letter_spacing
+word_spacing
+text_decoration
+textLength
+lengthAdjust
+x
+xml_space
+y
}
class SvgWhiteListEntry_tspan {
+clip_path
+clip_rule
+dx
+dy
+dominant_baseline
+fill
+fill_opacity
+fill_rule
+filter
+font_family
+font_size
+font_stretch
+font_style
+font_weight
+mask
+opacity
+requiredFeatures
+rotate
+stroke
+stroke_dasharray
+stroke_dashoffset
+stroke_linecap
+stroke_linejoin
+stroke_miterlimit
+stroke_opacity
+stroke_width
+systemLanguage
+text_anchor
+textLength
+x
+xml_space
+y
}
SvgSanitizer --> SvgWhiteListEntry_g : uses
SvgSanitizer --> SvgWhiteListEntry_symbol : uses
SvgSanitizer --> SvgWhiteListEntry_text : uses
SvgSanitizer --> SvgWhiteListEntry_tspan : uses
Flow diagram for SVG sanitization with preserved font-stretchflowchart TD
UserSVG["User-provided SVG with font-stretch"] --> Sanitizer
Sanitizer["sanitizeSvg"] --> CheckWhitelist["Check svgWhiteList_ for each element/attribute"]
CheckWhitelist -->|font-stretch on g/symbol/text/tspan| KeepAttr["Keep attribute in sanitized SVG"]
CheckWhitelist -->|non-whitelisted attributes| DropAttr["Strip attribute"]
KeepAttr --> SanitizedSVG["Sanitized SVG rendered with font-stretch"]
DropAttr --> SanitizedSVG
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Since the same set of font-related attributes is now repeated across
g,symbol,text, andtspan, consider extracting a sharedFONT_ATTRIBUTESarray and spreading it into each element’s whitelist to reduce duplication and the chance of future inconsistencies.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Since the same set of font-related attributes is now repeated across `g`, `symbol`, `text`, and `tspan`, consider extracting a shared `FONT_ATTRIBUTES` array and spreading it into each element’s whitelist to reduce duplication and the chance of future inconsistencies.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
…etter maintainability and consistency across SVG elements
jfhenon
approved these changes
Jan 30, 2026
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.
PR description
Adds font-stretch to the sanitizer whitelist (svgWhiteList_) so the attribute is kept when SVG is sanitized, instead of being stripped.
Checklist
Note that we require UI tests to ensure that the added feature will not be
nixed by some future fix and that there is at least some test-as-documentation
to indicate how the fix or enhancement is expected to behave.
npm test, ensuring linting passes and that Cypress UI tests keepcoverage to at least the same percent (reflected in the coverage badge
that should be updated after the tests run)
help both for future users and for the PR reviewer.
Summary by Sourcery
Bug Fixes: