Skip to content

Commit eaa8b5d

Browse files
Viz export: remove clear default namespaces (T1292204) (DevExpress#29907)
1 parent a015ae7 commit eaa8b5d

File tree

2 files changed

+38
-20
lines changed

2 files changed

+38
-20
lines changed

packages/devextreme/js/__internal/core/utils/m_svg.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,10 @@ function getMarkup(element, backgroundColor) {
1616
}
1717

1818
function fixNamespaces(markup) {
19-
let first = true;
20-
2119
if (markup.indexOf('xmlns:xlink') === -1) {
2220
markup = markup.replace('<svg', '<svg xmlns:xlink="http://www.w3.org/1999/xlink"');
2321
}
2422

25-
markup = markup.replace(/xmlns="[\s\S]*?"/gi, function (match) {
26-
if (!first) return '';
27-
first = false;
28-
return match;
29-
});
30-
3123
return markup.replace(/xmlns:NS1="[\s\S]*?"/gi, '')
3224
.replace(/NS1:xmlns:xlink="([\s\S]*?)"/gi, 'xmlns:xlink="$1"');
3325
}

packages/devextreme/testing/tests/DevExpress.viz.renderers/SvgElement.tests.js

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -487,20 +487,21 @@ function checkDashStyle(assert, elem, result, style, value) {
487487

488488
QUnit.module('SvgElement markup method');
489489

490-
QUnit.test('Returns correct namespaces (IE specific problem)', function(assert) {
491-
function mapFromStr(str) {
492-
const map = {};
493-
str.split('>').forEach(function(s) {
494-
s.split('<').forEach(function(s) {
495-
s.split(' ').forEach(function(s) {
496-
if(s) {
497-
map[s] = (map[s] || 0) + 1;
498-
}
499-
});
490+
function mapFromStr(str) {
491+
const map = {};
492+
str.split('>').forEach(function(s) {
493+
s.split('<').forEach(function(s) {
494+
s.split(' ').forEach(function(s) {
495+
if(s) {
496+
map[s] = (map[s] || 0) + 1;
497+
}
500498
});
501499
});
502-
return map;
503-
}
500+
});
501+
return map;
502+
}
503+
504+
QUnit.test('Returns correct namespaces (IE specific problem)', function(assert) {
504505
// arrange
505506
const parent = { element: document.createElement('div') };
506507
const svg = (new rendererModule.SvgElement({}, 'svg')).append(parent);
@@ -521,6 +522,31 @@ function checkDashStyle(assert, elem, result, style, value) {
521522
assert.deepEqual(mapFromStr(markupString), mapFromStr('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">Some content</svg>'));
522523
});
523524

525+
QUnit.test('Keep all default namespaces (T1292204)', function(assert) {
526+
// arrange
527+
const parent = { element: document.createElement('div') };
528+
const svg = (new rendererModule.SvgElement({}, 'svg')).append(parent);
529+
$('#qunit-fixture').append(parent);
530+
531+
svg.attr({
532+
xmlns: 'http://www.w3.org/2000/svg',
533+
'xmlns:xlink': 'http://www.w3.org/1999/xlink',
534+
version: '1.1'
535+
});
536+
537+
const foreignContent = document.createElement('table');
538+
foreignContent.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
539+
540+
svg.element.appendChild(foreignContent);
541+
542+
// act
543+
const markupString = svg.markup();
544+
const expectedMarkup = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"><table xmlns="http://www.w3.org/1999/xhtml"></table></svg>';
545+
546+
// assert
547+
assert.deepEqual(mapFromStr(markupString), mapFromStr(expectedMarkup));
548+
});
549+
524550
QUnit.test('Can return markup on detached element', function(assert) {
525551
// arrange
526552
const svg = (new rendererModule.SvgElement({}, 'svg'));

0 commit comments

Comments
 (0)