Skip to content

Commit

Permalink
Improved parser error messages, #20
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Puzrin committed Jan 3, 2016
1 parent 32119ad commit bb2a254
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2.1.5 / WIP
------------------

- Improved parser error messages.


2.1.4 / 2016-01-03
------------------

Expand Down
9 changes: 8 additions & 1 deletion lib/path_parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down
1 change: 1 addition & 0 deletions test/path_parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)');
Expand Down

0 comments on commit bb2a254

Please sign in to comment.