From 77472aabea2e3c52b4c50be6cc585e3b65041008 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 8 Jan 2024 14:58:19 +0100 Subject: [PATCH] :sparkles: Add path parser js impl more resilent to parse errors --- common/src/app/common/svg/path/parser.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/common/src/app/common/svg/path/parser.js b/common/src/app/common/svg/path/parser.js index 804112f073..5bbcddd3a0 100644 --- a/common/src/app/common/svg/path/parser.js +++ b/common/src/app/common/svg/path/parser.js @@ -916,11 +916,21 @@ function simplifyPathData(pdata) { export function parse(string) { if (!string || string.length === 0) return []; - var source = new Parser(string); - var result = Array.from(source); + try { + var source = new Parser(string); + var result = Array.from(source); - result = absolutizePathData(result); - result = simplifyPathData(result); + result = absolutizePathData(result); + result = simplifyPathData(result); - return result; + return result; + } catch (cause) { + const msg = "unexpected exception parsing path"; + console.group(msg); + console.log(`string: ${string}`) + console.error(cause); + console.groupEnd(msg); + + return []; + } }