From 5631279f99c521e7ddd5cb00131bdabddbc38979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ju=CC=88rg=20Lehni?= Date: Sat, 23 May 2020 13:40:07 +0200 Subject: [PATCH] Support SVG strings with leading line-breaks Closes #1813 --- src/svg/SvgImport.js | 14 ++++++++++---- test/tests/SvgImport.js | 10 ++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/svg/SvgImport.js b/src/svg/SvgImport.js index 1ad28fb4..b9e8d9ef 100644 --- a/src/svg/SvgImport.js +++ b/src/svg/SvgImport.js @@ -662,8 +662,12 @@ new function() { function onLoad(svg) { try { - var node = typeof svg === 'object' ? svg : new self.DOMParser() - .parseFromString(svg, 'image/svg+xml'); + var node = typeof svg === 'object' + ? svg + : new self.DOMParser().parseFromString( + svg, + 'image/svg+xml' + ); if (!node.nodeName) { node = null; throw new Error('Unsupported SVG source: ' + source); @@ -693,8 +697,10 @@ new function() { // Have the group not pass on all transformations to its children, // as this is how SVG works too. - // See if it's a string but handle markup separately - if (typeof source === 'string' && !/^.*\n \n\n' + var imported = paper.project.importSVG(svg); + equals(imported.children.length, 1); + equals(imported.firstChild, new Shape.Rectangle({ + size: [100, 100], + fillColor: 'red' + })); +}); + function importSVG(assert, url, message, options) { var done = assert.async(); project.importSVG(url, {