1
0
mirror of https://github.com/svg/svgo.git synced 2025-07-31 07:44:22 +03:00

Fix scientific notation parsing in paths

This commit is contained in:
Bogdan Chadkin
2021-03-02 11:47:29 +03:00
parent c1b8c3e261
commit d6f972c970
2 changed files with 7 additions and 2 deletions

View File

@ -58,7 +58,7 @@ const readNumber = (string, cursor) => {
continue; continue;
} }
if (state === 'e') { if (state === 'e') {
state === 'exponent_sign'; state = 'exponent_sign';
value += c; value += c;
continue; continue;
} }
@ -216,7 +216,7 @@ const stringifyNumber = ({ number, precision }) => {
} else { } else {
result = number.toFixed(precision); result = number.toFixed(precision);
if (result.includes('.')) { if (result.includes('.')) {
result = result.replace(/\.?0+$/, '') result = result.replace(/\.?0+$/, '');
} }
} }
// remove zero whole from decimal number // remove zero whole from decimal number

View File

@ -47,6 +47,11 @@ describe('parse path data', () => {
expect(parsePathData('L 10 20')).to.deep.equal([]); expect(parsePathData('L 10 20')).to.deep.equal([]);
expect(parsePathData('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', () => { it('should stop on invalid numbers', () => {
expect(parsePathData('M ...')).to.deep.equal([]); expect(parsePathData('M ...')).to.deep.equal([]);
}); });