Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Commit

Permalink
fix(isSvg): return false when is-svg package throw an Error (Invalid …
Browse files Browse the repository at this point in the history
…XML for example)
  • Loading branch information
fraxken committed Apr 3, 2022
1 parent b875403 commit 0de90e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ import { toValue } from "./literal.js";
* @returns {boolean}
*/
export function isSvg(strOrLiteral) {
const value = toValue(strOrLiteral);
try {
const value = toValue(strOrLiteral);

return isStringSvg(value) || isSvgPath(value);
return isStringSvg(value) || isSvgPath(value);
}
catch {
return false;
}
}

/**
Expand Down
5 changes: 5 additions & 0 deletions test/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ test("isSvg of a SVG Path must return true", (tape) => {
tape.end();
});

test("isSvg must return false for invalid XML string", (tape) => {
tape.strictEqual(isSvg("</a>"), false);
tape.end();
});

test("isSvgPath must return true when we give a valid svg path and false when the string is not valid", (tape) => {
tape.strictEqual(isSvgPath("M150 0 L75 200 L225 200 Z"), true);
tape.strictEqual(isSvgPath("M150"), false, "the length of an svg path must be always higher than four characters");
Expand Down

0 comments on commit 0de90e6

Please sign in to comment.