Skip to content

fix(shared): escape attribute values in buildLucideSvg - #4940

Merged
karsa-mistmere merged 4 commits into
lucide-icons:mainfrom
Saadanjum0:fix/escape-svg-attribute-values
Oct 2, 2026
Merged

karsa-mistmere merged 4 commits into
lucide-icons:mainfrom
Saadanjum0:fix/escape-svg-attribute-values

Conversation

@Saadanjum0

Copy link
Copy Markdown
Contributor

Problem

buildLucideSvg (and buildLucideDataUri, which wraps it) interpolates attribute values into the SVG string without escaping. A value such as a "quoted" & b passed through attributes or className yields malformed SVG and lets the value break out of the attribute.

Cause

buildDomNode in packages/shared/src/build/buildLucideSvg.ts builds name="${String(value)}" directly.

Fix

Escape &, " and < in attribute values before interpolation.

Testing

Added packages/shared/tests/buildLucideSvg.spec.ts; it fails without the change and passes with it. Full packages/shared vitest suite passes (52 tests).

Attribute values were interpolated into the SVG string as-is, so a value
containing a double quote, ampersand or angle bracket (for example in a
custom attribute or class name) produced malformed markup.
Copilot AI balanced review requested due to automatic review settings October 1, 2026 20:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@karsa-mistmere karsa-mistmere left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Saadanjum0,

Nice catch, thanks for looking into this and fixing it, I have one proposed change, otherwise this is good to go.

Comment on lines +4 to +5
const escapeAttribute = (value: string) =>
value.replaceAll('&', '&amp;').replaceAll('"', '&quot;').replaceAll('<', '&lt;');

This comment was marked as outdated.

lucide-react-native's tsconfig doesn't include the ES2021 lib that
replaceAll requires, failing typecheck. A global regex replace is
functionally identical here and works under any target.
Copilot AI balanced review requested due to automatic review settings October 2, 2026 07:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment on lines +4 to +5
const escapeAttribute = (value: string) =>
value.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated suggestion:

Suggested change
const escapeAttribute = (value: string) =>
value.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;');
const entities = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#39;',
} as const;
const escapeAttribute = (value: string) =>
value.replace(/[&<>"']/g, char => entities[char as keyof typeof entities]);

Also escape > and ' per review feedback, not just & " <.
Copilot AI balanced review requested due to automatic review settings October 2, 2026 07:33
@Saadanjum0

Copy link
Copy Markdown
Contributor Author

Updated — now escaping the full set via an entities map, including > and '. Thanks for the review!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI balanced review requested due to automatic review settings October 2, 2026 07:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@karsa-mistmere
karsa-mistmere merged commit e8a2c60 into lucide-icons:main Oct 2, 2026
30 checks passed
brandhaug added a commit to brandhaug/b2b-saas-starter that referenced this pull request Oct 5, 2026
## pnpm-workspace.yaml (default)

## Dependency Updates

| Package | From | To | Type |
| --- | --- | --- | --- |
| `lucide-react` | 1.49.0 | 1.50.0 | minor |

## Release Notes

<details>
<summary><b>lucide-react</b> (1.49.0 → 1.50.0)</summary>

## What's Changed
* fix(shared): escape attribute values in buildLucideSvg by
@<!---->Saadanjum0 in lucide-icons/lucide#4940
* fix(github/actions): use canonical metadata instructions for PR
suggestions by @<!---->karsa-mistmere in
lucide-icons/lucide#4910
* fix(icons): replaced `nut` & `nut-off` with compliant designs by
@<!---->karsa-mistmere in
lucide-icons/lucide#4840
* chore(deps-dev): bump @<!---->angular/router from 22.1.7 to 22.2.0 by
@<!---->dependabot[bot] in
lucide-icons/lucide#4945
* chore(deps): bump next from 16.3.4 to 16.3.6 by
@<!---->dependabot[bot] in
lucide-icons/lucide#4946
* chore(deps-dev): bump the svelte-deps group with 2 updates by
@<!---->dependabot[bot] in
lucide-icons/lucide#4918
* test(integrations): add Vue integration fixtures for Vite, Nuxt and
Vike by @<!---->ericfennis in
lucide-icons/lucide#4882
* feat(svelte): export context subpath by @<!---->vugarbbakhishov-hub in
lucide-icons/lucide#4927
* fix(lucide-preact): add Preact v11 compatibility by
@<!---->JoviDeCroock in lucide-icons/lucide#4924
* feat(icons): added `layout-grid-circles` icon by
@<!---->karsa-mistmere in
lucide-icons/lucide#4567

## New Contributors
* @<!---->Saadanjum0 made their first contribution in
lucide-icons/lucide#4940
* @<!---->JoviDeCroock made their first contribution in
lucide-icons/lucide#4924

**Full Changelog**:
lucide-icons/lucide@1.49.0...1.50.0

</details>

---
*This PR was auto-generated by
[catalog-update-action](https://github.com/brandhaug/catalog-update-action).*

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants