Skip to content

Commit

Permalink
fix: do not parse id as number in any case (#2563)
Browse files Browse the repository at this point in the history
# Summary

When using `SvgXml` or `SvgCss`, an `id` attribute gets converted into a
`number` instead of a `string`, which causes a crash because the native
side expects a string value.

```js
import {SvgXml} from 'react-native-svg';
import {SvgCss} from 'react-native-svg/css';
```

## Test Plan

This example should not crash:
```jsx
import {SvgCss} from 'react-native-svg/css';

const svgXml = `
<svg width="100" height="100" viewBox="0 0 100 100">
  <filter x="0%" y="0%" width="100" height="100" id="0123456789">
    <feFlood flood-color="red" />
  </filter>
  <circle cx="50" cy="50" r="50" filter="url(#0123456789)" />
</svg>
`;

function Example() {
  return <SvgCss xml={svgXml} />;
}
```
  • Loading branch information
jakex7 authored Dec 5, 2024
1 parent 3b5c5f0 commit 4886135
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/xml.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ export function parse(source: string, middleware?: Middleware): JsxAST | null {
allowSpaces();

value = getAttributeValue();
if (!isNaN(+value) && value.trim() !== '') {
if (name !== 'id' && !isNaN(+value) && value.trim() !== '') {
value = +value;
}
}
Expand Down

0 comments on commit 4886135

Please sign in to comment.