Skip to content

Commit dde2bdf

Browse files
authored
Merge pull request #541 from NateScarlet/fix-default-namespace
Fix issues caused by missing config reset
2 parents f4e594a + 4fbbdf6 commit dde2bdf

10 files changed

+60
-17
lines changed

dist/purify.cjs.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.cjs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.es.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.es.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/purify.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ function createDOMPurify(window = getGlobal()) {
384384
KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
385385
IN_PLACE = cfg.IN_PLACE || false; // Default false
386386
IS_ALLOWED_URI = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
387-
NAMESPACE = cfg.NAMESPACE || NAMESPACE;
387+
NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
388388
if (SAFE_FOR_TEMPLATES) {
389389
ALLOW_DATA_ATTR = false;
390390
}
@@ -1106,9 +1106,9 @@ function createDOMPurify(window = getGlobal()) {
11061106
/* Make sure we have a string to sanitize.
11071107
DO NOT return early, as this will return the wrong type if
11081108
the user has requested a DOM object rather than a string */
1109-
if (!dirty) {
1109+
IS_EMPTY_INPUT = !dirty;
1110+
if (IS_EMPTY_INPUT) {
11101111
dirty = '<!-->';
1111-
IS_EMPTY_INPUT = true;
11121112
}
11131113

11141114
/* Stringify, in case dirty is an object */

test/test-suite.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,4 +1615,47 @@ module.exports = function (DOMPurify, window, tests, xssTests) {
16151615
assert.contains(clean, test.expected);
16161616
});
16171617
});
1618+
1619+
QUnit.test('Test namespace default to html after other namespace been used', function (assert) {
1620+
var tests = [
1621+
{
1622+
test: '<br>',
1623+
config: { NAMESPACE: 'http://www.w3.org/2000/svg' },
1624+
expected: [''],
1625+
},
1626+
{
1627+
test: '<br>',
1628+
config: { },
1629+
expected: ['<br>'],
1630+
},
1631+
];
1632+
tests.forEach(function (test) {
1633+
var clean = DOMPurify.sanitize(test.test, test.config);
1634+
assert.contains(clean, test.expected);
1635+
});
1636+
});
1637+
1638+
QUnit.test('Test non-html input after empty input', function (assert) {
1639+
var tests = [
1640+
{
1641+
test: '',
1642+
config: { NAMESPACE: 'http://www.w3.org/2000/svg' },
1643+
expected: [''],
1644+
},
1645+
{
1646+
test: '<polyline points="0 0"></polyline>',
1647+
config: { NAMESPACE: 'http://www.w3.org/2000/svg' },
1648+
expected: [
1649+
'<polyline points="0 0"></polyline>',
1650+
'<polyline xmlns="http://www.w3.org/2000/svg" points="0 0"/>',
1651+
'<polyline xmlns="http://www.w3.org/2000/svg" points="0,0" />',
1652+
'',
1653+
],
1654+
},
1655+
];
1656+
tests.forEach(function (test) {
1657+
var clean = DOMPurify.sanitize(test.test, test.config);
1658+
assert.contains(clean, test.expected);
1659+
});
1660+
});
16181661
};

0 commit comments

Comments
 (0)