2
0
mirror of https://github.com/iconify/iconify.git synced 2025-01-06 07:20:40 +00:00

Fix double spacing in attributes in mergeIconProps in utils

This commit is contained in:
Vjacheslav Trushkin 2022-03-18 15:52:53 +02:00
parent 29a88a2753
commit a7899d812f
3 changed files with 22 additions and 12 deletions

View File

@ -3,7 +3,7 @@
"type": "module",
"description": "Common functions for working with Iconify icon sets used by various packages.",
"author": "Vjacheslav Trushkin",
"version": "1.0.25",
"version": "1.0.26",
"license": "MIT",
"bugs": "https://github.com/iconify/iconify/issues",
"homepage": "https://iconify.design/",

View File

@ -70,17 +70,16 @@ export async function mergeIconProps(
}
}
svg = svg.replace(
'<svg ',
`<svg ${Object.keys(props)
.map((p) =>
(p === 'width' && widthOnSvg) || (p === 'height' && heightOnSvg)
? null
: `${p}="${props[p]}"`
)
.filter((p) => p != null)
.join(' ')} `
);
const propsToAdd = Object.keys(props)
.map((p) =>
(p === 'width' && widthOnSvg) || (p === 'height' && heightOnSvg)
? null
: `${p}="${props[p]}"`
)
.filter((p) => p != null);
if (propsToAdd.length) {
svg = svg.replace('<svg ', `<svg ${propsToAdd.join(' ')} `);
}
if (svg && options) {
const { defaultStyle, defaultClass } = options;

View File

@ -11,6 +11,17 @@ describe('Testing getCustomIcon', () => {
expect(svg).toEqual(result);
});
test('CustomIconLoader without xmlns', async () => {
const svg =
'<svg viewBox="0 0 120 120"><circle cx="60" cy="60" r="50"/></svg>';
const result = await getCustomIcon(() => svg, 'a', 'b', {
addXmlNs: true,
});
expect(result).toEqual(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 120 120"><circle cx="60" cy="60" r="50"/></svg>'
);
});
test("CustomIconLoader with transform: scale/width/height shouldn't take effect", async () => {
const svg = await fs.readFile(fixturesDir + '/circle.svg', 'utf8');
const options: IconifyLoaderOptions = {