xyc
2025-02-21 664db98c9e8595ce4dd636a27f480e3a08b81ff5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* eslint-env qunit */
import {NS} from '../editor/namespaces.js';
import * as sanitize from '../editor/sanitize.js';
 
// log function
QUnit.log((details) => {
  if (window.console && window.console.log) {
    window.console.log(details.result + ' :: ' + details.message);
  }
});
 
const svg = document.createElementNS(NS.SVG, 'svg');
 
QUnit.test('Test sanitizeSvg() strips ws from style attr', function (assert) {
  assert.expect(2);
 
  const rect = document.createElementNS(NS.SVG, 'rect');
  rect.setAttribute('style', 'stroke: blue ;        stroke-width :        40;');
  // sanitizeSvg() requires the node to have a parent and a document.
  svg.append(rect);
  sanitize.sanitizeSvg(rect);
 
  assert.equal(rect.getAttribute('stroke'), 'blue');
  assert.equal(rect.getAttribute('stroke-width'), '40');
});