Skip to content

Commit

Permalink
fix(SVGImport): Skip id attribute from normalization (#10079)
Browse files Browse the repository at this point in the history
  • Loading branch information
miroljub1995 authored Aug 26, 2024
1 parent cbfba61 commit 03c426f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## [next]

- fix(SVGImport): Allow parsing of 'id' attribute that starts with a number [#10079](https://github.com/fabricjs/fabric.js/pull/10079)
- fix(filter): pixelate filter has non square pixels in webgl (#10081)
- feat(Canvas): Avoid styling the lower canvas with absolute positioning [#10077](https://github.com/fabricjs/fabric.js/pull/10077)
- chore(TS): Add missing export type for Text events [#10076](https://github.com/fabricjs/fabric.js/pull/10076)
Expand Down
14 changes: 14 additions & 0 deletions src/parser/loadSVGFromString.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Path } from '../shapes/Path';
import { Rect } from '../shapes/Rect';
import { loadSVGFromString } from './loadSVGFromString';

describe('loadSVGFromString', () => {
Expand Down Expand Up @@ -30,4 +31,17 @@ describe('loadSVGFromString', () => {
expect(parsedSvg.objects[0] instanceof Path).toBe(true);
}
});

it('returns successful parse of svg with id starting with number', async () => {
const str = `<svg viewBox="0 0 128 128" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect id="123xyz" width="10" height="10" />
</svg>`;

const parsedSvg = await loadSVGFromString(str);

expect(
parsedSvg.objects[0] instanceof Rect &&
(parsedSvg.objects[0] as Rect & { id: string }).id,
).toBe('123xyz');
});
});
7 changes: 6 additions & 1 deletion src/parser/normalizeValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ export function normalizeValue(
} else if (fillIndex === -1 && strokeIndex > -1) {
ouputValue = STROKE;
}
} else if (attr === 'href' || attr === 'xlink:href' || attr === 'font') {
} else if (
attr === 'href' ||
attr === 'xlink:href' ||
attr === 'font' ||
attr === 'id'
) {
return value;
} else if (attr === 'imageSmoothing') {
return value === 'optimizeQuality';
Expand Down

0 comments on commit 03c426f

Please sign in to comment.