Skip to content

Commit

Permalink
Fix scientific notation parsing in paths
Browse files Browse the repository at this point in the history
  • Loading branch information
TrySound committed Mar 2, 2021
1 parent c1b8c3e commit d6f972c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const readNumber = (string, cursor) => {
continue;
}
if (state === 'e') {
state === 'exponent_sign';
state = 'exponent_sign';
value += c;
continue;
}
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
});
Expand Down

0 comments on commit d6f972c

Please sign in to comment.