diff --git a/src/path/parser.js b/src/path/parser.js index d6b5620..384403c 100644 --- a/src/path/parser.js +++ b/src/path/parser.js @@ -9,7 +9,7 @@ export default function parser(pathString) let segmentMatch segmentExpr.lastIndex = 0 - + while( (segmentMatch = segmentExpr.exec(pathString)) ) { const type = segmentMatch[1].toLowerCase() @@ -20,7 +20,7 @@ export default function parser(pathString) if(numbers.length < schema.length) { - throw new Error(`Malformed path data: type "${type}" has ${numbers.length} arguments, expected ${scheme.length}`) + throw new Error(`Malformed path data: type "${type}" has ${numbers.length} arguments, expected ${schema.length}`) } if(schema.length > 0) diff --git a/test/path/parser.js b/test/path/parser.js index ba84c75..ef7f8c5 100644 --- a/test/path/parser.js +++ b/test/path/parser.js @@ -7,7 +7,7 @@ describe('parser()', function() { assert.deepEqual([], parser(' ')) }) - + it('should parse space separated path string', function() { assert.deepEqual([ @@ -66,4 +66,18 @@ describe('parser()', function() { type: 'z', relative: false }, ], parser('M 0,1 L 2,3 Z')) }) + + it('should detect too few arguments', function() + { + assert.throws(() => { + parser('A 110 110 0 0') + }, {message: /Malformed path data/}) + }) + + it('should detect too many arguments', function() + { + assert.throws(() => { + parser('a 110 110 0 0 1 55 -7 42') + }, {message: /Malformed path data/}) + }) })