Skip to content

Commit

Permalink
svgo-worker/index.js: be stricter with the checks
Browse files Browse the repository at this point in the history
SVGO returns `undefined` when an attribute isn't present, not `null`.
  • Loading branch information
XhmikosR committed Oct 18, 2021
1 parent 20e5474 commit b925d7a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
8 changes: 0 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@
"rules": {
"arrow-body-style": "off",
"capitalized-comments": "off",
"eqeqeq": [
"error",
"always",
{
"null": "ignore"
}
],
"no-eq-null": "off",
"no-multi-assign": "off",
"no-negated-condition": "off",
"no-shadow": "error",
Expand Down
7 changes: 5 additions & 2 deletions src/js/svgo-worker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ const createDimensionsExtractor = () => {
// Node, parentNode
enter: ({ name, attributes }, { type }) => {
if (name === 'svg' && type === 'root') {
if (attributes.width != null && attributes.height !== null) {
if (
attributes.width !== undefined &&
attributes.height !== undefined
) {
dimensions.width = Number.parseFloat(attributes.width);
dimensions.height = Number.parseFloat(attributes.height);
} else if (attributes.viewBox != null) {
} else if (attributes.viewBox !== undefined) {
const viewBox = attributes.viewBox.split(/,\s*|\s+/);
dimensions.width = Number.parseFloat(viewBox[2]);
dimensions.height = Number.parseFloat(viewBox[3]);
Expand Down

0 comments on commit b925d7a

Please sign in to comment.