From d0328d4571f65d78800375a1248a30ba143cbc16 Mon Sep 17 00:00:00 2001 From: adroitwhiz Date: Sat, 16 May 2020 04:41:25 -0400 Subject: [PATCH 1/3] Don't set numeric item names in SVG import --- src/svg/SvgImport.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/svg/SvgImport.js b/src/svg/SvgImport.js index 99066034..1ba04952 100644 --- a/src/svg/SvgImport.js +++ b/src/svg/SvgImport.js @@ -445,7 +445,9 @@ new function() { }, {}), { id: function(item, value) { definitions[value] = item; - if (item.setName) + // Same check used in setName to test if IDs are numeric. Numeric IDs make setName throw an exception. + // Better to duplicate the check than to wrap this in a try block & swallow all other potential exceptions. + if (item.setName && ((+value) + '' !== value)) item.setName(value); }, From 3e4927f6be431afc7106b8419ae4aa82216a007e Mon Sep 17 00:00:00 2001 From: adroitwhiz Date: Sat, 16 May 2020 04:52:00 -0400 Subject: [PATCH 2/3] Add test for numeric SVG ID import --- test/tests/SvgImport.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/tests/SvgImport.js b/test/tests/SvgImport.js index a8c1f145..94477b25 100644 --- a/test/tests/SvgImport.js +++ b/test/tests/SvgImport.js @@ -168,6 +168,16 @@ test('Import SVG string with leading line-breaks', function() { })); }); +test('Import SVG with numeric ID', function() { + paper.project.importSVG(createSVG('circle', { + cx: 100, + cy: 100, + r: 50, + id: '1' + })); + ok(true, 'Imports SVG with a numeric element ID without throwing.'); +}); + function importSVG(assert, url, message, options) { var done = assert.async(); project.importSVG(url, { From 54d776557ff9a594eb6d8cbdbc09521a8023aa81 Mon Sep 17 00:00:00 2001 From: adroitwhiz Date: Thu, 25 Jun 2020 15:40:08 -0400 Subject: [PATCH 3/3] Don't import SVG IDs at all --- src/svg/SvgImport.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/svg/SvgImport.js b/src/svg/SvgImport.js index 1ba04952..f58c8c02 100644 --- a/src/svg/SvgImport.js +++ b/src/svg/SvgImport.js @@ -445,10 +445,6 @@ new function() { }, {}), { id: function(item, value) { definitions[value] = item; - // Same check used in setName to test if IDs are numeric. Numeric IDs make setName throw an exception. - // Better to duplicate the check than to wrap this in a try block & swallow all other potential exceptions. - if (item.setName && ((+value) + '' !== value)) - item.setName(value); }, 'clip-path': function(item, value) {