From d6f972c970d3cdd68ccc740e1a610ff0b23fcd34 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Tue, 2 Mar 2021 11:47:29 +0300 Subject: [PATCH] Fix scientific notation parsing in paths --- lib/path.js | 4 ++-- lib/path.test.js | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/path.js b/lib/path.js index 45934329..f37f12ea 100644 --- a/lib/path.js +++ b/lib/path.js @@ -58,7 +58,7 @@ const readNumber = (string, cursor) => { continue; } if (state === 'e') { - state === 'exponent_sign'; + state = 'exponent_sign'; value += c; continue; } @@ -216,7 +216,7 @@ const stringifyNumber = ({ number, precision }) => { } else { result = number.toFixed(precision); if (result.includes('.')) { - result = result.replace(/\.?0+$/, '') + result = result.replace(/\.?0+$/, ''); } } // remove zero whole from decimal number diff --git a/lib/path.test.js b/lib/path.test.js index a677f8dc..eca120c2 100644 --- a/lib/path.test.js +++ b/lib/path.test.js @@ -47,6 +47,11 @@ describe('parse path data', () => { expect(parsePathData('L 10 20')).to.deep.equal([]); expect(parsePathData('10 20')).to.deep.equal([]); }); + it('should stop on invalid scientific notation', () => { + expect(parsePathData('M 0 5e++1 L 0 0')).to.deep.equal([ + { command: 'M', args: [0, 5] }, + ]); + }); it('should stop on invalid numbers', () => { expect(parsePathData('M ...')).to.deep.equal([]); });