diff --git a/CHANGELOG.md b/CHANGELOG.md index 2289ab9..4398ba9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +2.1.5 / WIP +------------------ + +- Improved parser error messages. + + 2.1.4 / 2016-01-03 ------------------ diff --git a/lib/path_parse.js b/lib/path_parse.js index ebdec04..fe16e67 100644 --- a/lib/path_parse.js +++ b/lib/path_parse.js @@ -38,6 +38,13 @@ function isDigit(code) { return (code >= 48 && code <= 57); // 0..9 } +function isDigitStart(code) { + return (code >= 48 && code <= 57) || /* 0..9 */ + code === 0x2B || /* + */ + code === 0x2D || /* - */ + code === 0x2E; /* . */ +} + function State(path) { this.index = 0; @@ -233,7 +240,7 @@ function scanSegment(state) { } // Stop on next segment - if (isCommand(state.path.charCodeAt(state.index))) { + if (!isDigitStart(state.path.charCodeAt(state.index))) { break; } } diff --git a/test/path_parse.js b/test/path_parse.js index fabe549..486a587 100644 --- a/test/path_parse.js +++ b/test/path_parse.js @@ -50,6 +50,7 @@ describe('Path parse', function () { it('errors', function () { assert.equal(svgpath('0').err, 'SvgPath: bad command 0 (at pos 0)'); assert.equal(svgpath('U').err, 'SvgPath: bad command U (at pos 0)'); + assert.equal(svgpath('M0 0G 1').err, 'SvgPath: bad command G (at pos 4)'); assert.equal(svgpath('z').err, 'SvgPath: string should start with `M` or `m`'); assert.equal(svgpath('M+').err, 'SvgPath: param should start with 0..9 or `.` (at pos 2)'); assert.equal(svgpath('M00').err, 'SvgPath: numbers started with `0` such as `09` are ilegal (at pos 1)');