svg/svgo

v3.2.0 'Cannot read properties of undefined' error in reflectPoint

benjaminion opened this issue · 1 comments

Describe the bug

In version 3.2.0 svgo fails on certain files with the following error when using the convertPathData plugin. The issue does not occur in v3.1.0 and earlier.

/tmp/node_modules/svgo/plugins/convertPathData.js:1160
  return [2 * base[0] - controlPoint[0], 2 * base[1] - controlPoint[1]];
                                    ^

TypeError: Cannot read properties of undefined (reading '0')
    at reflectPoint (/tmp/node_modules/svgo/plugins/convertPathData.js:1160:37)
    at /tmp/node_modules/svgo/plugins/convertPathData.js:802:43
    at Array.filter (<anonymous>)
    at filters (/tmp/node_modules/svgo/plugins/convertPathData.js:397:15)
    at Object.enter (/tmp/node_modules/svgo/plugins/convertPathData.js:183:20)
    at visit (/tmp/node_modules/svgo/lib/xast.js:52:30)
    at visit (/tmp/node_modules/svgo/lib/xast.js:68:9)
    at visit (/tmp/node_modules/svgo/lib/xast.js:68:9)
    at visit (/tmp/node_modules/svgo/lib/xast.js:68:9)
    at visit (/tmp/node_modules/svgo/lib/xast.js:68:9)

Node.js v20.6.1

An example file that triggers the error - the file validates with no issues.

To Reproduce
Run the following with the above file as input:

const svgo = require('svgo')
const fs = require('fs')

const originalSvg = fs.readFileSync('hysteresis.svg', 'utf8')
const svg = svgo.optimize(
  originalSvg,
  {
    plugins: ['convertPathData']
  }
)

Expected behavior
No errors.

Desktop (please complete the following information):

  • SVGO Version: 3.2.0
  • NodeJs Version 20.6.1
  • OS: Ubuntu 22.04.3 LTS

I'll see if I can get a fix in for this today. (if I could assign myself to it I would but I don't have the perms.)