From 314dfa35560ba8b90ce8ef6693daba39f00e2f6d Mon Sep 17 00:00:00 2001 From: Dylan Paulus Date: Wed, 8 Aug 2018 16:10:12 -0700 Subject: [PATCH 1/6] Add href support for parsing use directives (svg) --- src/parser.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parser.js b/src/parser.js index 82edc8abaaa..b5a01fed16f 100644 --- a/src/parser.js +++ b/src/parser.js @@ -464,7 +464,7 @@ while (nodelist.length && i < nodelist.length) { var el = nodelist[i], - xlink = el.getAttribute('xlink:href').substr(1), + xlink = (el.getAttribute('xlink:href') || el.getAttribute('href')).substr(1), x = el.getAttribute('x') || 0, y = el.getAttribute('y') || 0, el2 = elementById(doc, xlink).cloneNode(true), @@ -487,7 +487,7 @@ for (j = 0, attrs = el.attributes, len = attrs.length; j < len; j++) { attr = attrs.item(j); - if (attr.nodeName === 'x' || attr.nodeName === 'y' || attr.nodeName === 'xlink:href') { + if (attr.nodeName === 'x' || attr.nodeName === 'y' || attr.nodeName === 'xlink:href' || attr.nodeName === 'href') { continue; } From 1a916cce5b03da8e4c89089cf1382f28042cee77 Mon Sep 17 00:00:00 2001 From: Dylan Paulus Date: Wed, 8 Aug 2018 16:10:12 -0700 Subject: [PATCH 2/6] Add href support for parsing use directives (svg) --- src/parser.js | 4 ++-- test/unit/parser.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/parser.js b/src/parser.js index 82edc8abaaa..b5a01fed16f 100644 --- a/src/parser.js +++ b/src/parser.js @@ -464,7 +464,7 @@ while (nodelist.length && i < nodelist.length) { var el = nodelist[i], - xlink = el.getAttribute('xlink:href').substr(1), + xlink = (el.getAttribute('xlink:href') || el.getAttribute('href')).substr(1), x = el.getAttribute('x') || 0, y = el.getAttribute('y') || 0, el2 = elementById(doc, xlink).cloneNode(true), @@ -487,7 +487,7 @@ for (j = 0, attrs = el.attributes, len = attrs.length; j < len; j++) { attr = attrs.item(j); - if (attr.nodeName === 'x' || attr.nodeName === 'y' || attr.nodeName === 'xlink:href') { + if (attr.nodeName === 'x' || attr.nodeName === 'y' || attr.nodeName === 'xlink:href' || attr.nodeName === 'href') { continue; } diff --git a/test/unit/parser.js b/test/unit/parser.js index a90249b7f22..66a4a65c90e 100644 --- a/test/unit/parser.js +++ b/test/unit/parser.js @@ -372,6 +372,23 @@ }); }); + QUnit.test('parseSVGFromString with href', function(assert) { + var done = assert.async(); + var string = '' + + '' + + '' + + '', + rect; + + assert.ok(fabric.loadSVGFromString); + + fabric.loadSVGFromString(string, function(objects) { + rect = objects[0]; + assert.ok(rect instanceof fabric.Rect); + done(); + }); + }); + QUnit.test('parseSVGFromString nested opacity', function(assert) { var done = assert.async(); var string = '' + From 0be39fd6225760c4222188a8af69205891ee1191 Mon Sep 17 00:00:00 2001 From: Dylan Paulus Date: Wed, 8 Aug 2018 16:10:12 -0700 Subject: [PATCH 3/6] Add href support for parsing use directives (svg) --- src/parser.js | 4 ++-- test/unit/parser.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/parser.js b/src/parser.js index 82edc8abaaa..b5a01fed16f 100644 --- a/src/parser.js +++ b/src/parser.js @@ -464,7 +464,7 @@ while (nodelist.length && i < nodelist.length) { var el = nodelist[i], - xlink = el.getAttribute('xlink:href').substr(1), + xlink = (el.getAttribute('xlink:href') || el.getAttribute('href')).substr(1), x = el.getAttribute('x') || 0, y = el.getAttribute('y') || 0, el2 = elementById(doc, xlink).cloneNode(true), @@ -487,7 +487,7 @@ for (j = 0, attrs = el.attributes, len = attrs.length; j < len; j++) { attr = attrs.item(j); - if (attr.nodeName === 'x' || attr.nodeName === 'y' || attr.nodeName === 'xlink:href') { + if (attr.nodeName === 'x' || attr.nodeName === 'y' || attr.nodeName === 'xlink:href' || attr.nodeName === 'href') { continue; } diff --git a/test/unit/parser.js b/test/unit/parser.js index a90249b7f22..66a4a65c90e 100644 --- a/test/unit/parser.js +++ b/test/unit/parser.js @@ -372,6 +372,23 @@ }); }); + QUnit.test('parseSVGFromString with href', function(assert) { + var done = assert.async(); + var string = '' + + '' + + '' + + '', + rect; + + assert.ok(fabric.loadSVGFromString); + + fabric.loadSVGFromString(string, function(objects) { + rect = objects[0]; + assert.ok(rect instanceof fabric.Rect); + done(); + }); + }); + QUnit.test('parseSVGFromString nested opacity', function(assert) { var done = assert.async(); var string = '' + From 41fceef824634dadcdce29d5ecb8b05981daff63 Mon Sep 17 00:00:00 2001 From: Dylan Paulus Date: Wed, 8 Aug 2018 16:39:51 -0700 Subject: [PATCH 4/6] Fix linting errors --- src/parser.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/parser.js b/src/parser.js index b5a01fed16f..39e7fe1bc63 100644 --- a/src/parser.js +++ b/src/parser.js @@ -487,7 +487,8 @@ for (j = 0, attrs = el.attributes, len = attrs.length; j < len; j++) { attr = attrs.item(j); - if (attr.nodeName === 'x' || attr.nodeName === 'y' || attr.nodeName === 'xlink:href' || attr.nodeName === 'href') { + if (attr.nodeName === 'x' || attr.nodeName === 'y' || + attr.nodeName === 'xlink:href' || attr.nodeName === 'href') { continue; } From 65eb8d52e4a5e144e2e7ebc98f00e4f6f8ee8e31 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sun, 12 Aug 2018 23:23:50 +0200 Subject: [PATCH 5/6] add xlink:href test --- test/unit/parser.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/test/unit/parser.js b/test/unit/parser.js index 66a4a65c90e..c35c5a52c78 100644 --- a/test/unit/parser.js +++ b/test/unit/parser.js @@ -372,6 +372,23 @@ }); }); + QUnit.test('parseSVGFromString with xlink:href', function(assert) { + var done = assert.async(); + var string = '' + + '' + + '' + + '', + rect; + + assert.ok(fabric.loadSVGFromString); + + fabric.loadSVGFromString(string, function(objects) { + rect = objects[0]; + assert.ok(rect instanceof fabric.Rect); + done(); + }); + }); + QUnit.test('parseSVGFromString with href', function(assert) { var done = assert.async(); var string = '' + @@ -388,7 +405,7 @@ done(); }); }); - + QUnit.test('parseSVGFromString nested opacity', function(assert) { var done = assert.async(); var string = '' + From 9514df7acc64eb9097e211b9a0d5074abd5b8240 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Sun, 12 Aug 2018 23:30:59 +0200 Subject: [PATCH 6/6] Update parser.js --- test/unit/parser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/parser.js b/test/unit/parser.js index c35c5a52c78..ef58d22f8d5 100644 --- a/test/unit/parser.js +++ b/test/unit/parser.js @@ -405,7 +405,7 @@ done(); }); }); - + QUnit.test('parseSVGFromString nested opacity', function(assert) { var done = assert.async(); var string = '' +