From 3fb45ff6a797eee6dcab6f15a06611f791963d6b Mon Sep 17 00:00:00 2001 From: jheer Date: Fri, 25 Mar 2022 08:57:17 -0700 Subject: [PATCH] fix: Add SVG path parser null check. (#3451). --- packages/vega-scenegraph/src/path/parse.js | 3 ++- packages/vega-scenegraph/test/path-test.js | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/vega-scenegraph/src/path/parse.js b/packages/vega-scenegraph/src/path/parse.js index 7ed4e678ec..bfbf483baa 100644 --- a/packages/vega-scenegraph/src/path/parse.js +++ b/packages/vega-scenegraph/src/path/parse.js @@ -6,8 +6,9 @@ const flagPattern = /^[01]/; export default function parse(path) { const commands = []; + const matches = path.match(commandPattern) || []; - path.match(commandPattern).forEach(str => { + matches.forEach(str => { let cmd = str[0]; const type = cmd.toLowerCase(); diff --git a/packages/vega-scenegraph/test/path-test.js b/packages/vega-scenegraph/test/path-test.js index e8f3fedc48..64ff287378 100644 --- a/packages/vega-scenegraph/test/path-test.js +++ b/packages/vega-scenegraph/test/path-test.js @@ -111,6 +111,13 @@ tape('pathParse should parse svg path', t => { t.end(); }); +tape('pathParse should handle an empty string', t => { + const s = ''; + const p = []; + t.deepEqual(pathParse(s), p); + t.end(); +}); + tape('pathParse should handle repeated arguments', t => { const s = 'M 1 1 L 1 2 3 4'; const p = [['M',1,1], ['L',1,2], ['L',3,4]];