Skip to content

Commit

Permalink
Add test for stripping svg: tag prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adroitwhiz committed Jan 9, 2021
1 parent f9deabb commit e524fa4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/fixtures/svg-tag-prefixes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions test/fixup-svg-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,35 @@ test('fixupSvgString shouldn\'t correct non-attributes', t => {
t.end();
});

test('fixupSvgString should strip `svg:` prefix from tag names', t => {
const filePath = path.resolve(__dirname, './fixtures/svg-tag-prefixes.svg');
const svgString = fs.readFileSync(filePath)
.toString();
const fixed = fixupSvgString(svgString);

const checkPrefixes = element => {
t.notEqual(element.prefix, 'svg');
// JSDOM doesn't have element.children, only element.childNodes
if (element.childNodes) {
// JSDOM's childNodes is not iterable, so for...of cannot be used here
for (let i = 0; i < element.childNodes.length; i++) {
const child = element.childNodes[i];
if (child.nodeType === 1 /* Node.ELEMENT_NODE */) checkPrefixes(child);
}
}
};

// Make sure undefineds aren't being written into the file
t.equal(fixed.indexOf('undefined'), -1);
t.notThrow(() => {
domParser.parseFromString(fixed, 'text/xml');
});

checkPrefixes(domParser.parseFromString(fixed, 'text/xml'));

t.end();
});

test('fixupSvgString should empty script tags', t => {
const filePath = path.resolve(__dirname, './fixtures/script.svg');
const svgString = fs.readFileSync(filePath)
Expand Down

0 comments on commit e524fa4

Please # to comment.