-
Notifications
You must be signed in to change notification settings - Fork 110
fix(ui-svg-images): fix inlinesvg parser #2415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -199,8 +199,10 @@ class InlineSVG extends Component<InlineSVGProps> { | |
| function parseAttributes(src: InlineSVGProps['src']) { | ||
| const attributes: Record<string, string> = {} | ||
| const SVGAttributesRegExp = /<svg\s+([^>]*)\s*>/ | ||
| const namesAndValuesRegExp = | ||
| /(\S+)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?/g | ||
| // Match either quoted or unquoted attribute values | ||
| // Handles both standard format: attr="value" and non-standard: attr=value | ||
| // (\S+?) = attribute name, (?:["']([^"']*)["']|(\S+)) = quoted (group 2) OR unquoted (group 3) value | ||
| const namesAndValuesRegExp = /(\S+?)=(?:["']([^"']*)["']|(\S+))/g | ||
|
|
||
| if (typeof src === 'string') { | ||
| const attributesMatches = SVGAttributesRegExp.exec(src) | ||
|
|
@@ -211,10 +213,8 @@ function parseAttributes(src: InlineSVGProps['src']) { | |
|
|
||
| while (match != null) { | ||
| if (excludes.indexOf(match[1]) === -1) { | ||
| attributes[match[1]] = | ||
| match[2] || | ||
| (match[3] ? match[3] : match[4] ? match[4] : match[5]) || | ||
| match[1] | ||
|
Comment on lines
-214
to
-217
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont understand the old code here... how can there be 5 matches?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried it and |
||
| // match[1] = attribute name, match[2] = quoted value, match[3] = unquoted value | ||
| attributes[match[1]] = match[2] || match[3] | ||
| } | ||
| match = namesAndValuesRegExp.exec(attributesString) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would skip handling the non-standard format but we have to support it for backward compatibility.