Skip to content

Commit

Permalink
Merge pull request #790 from mukilane/main
Browse files Browse the repository at this point in the history
fix: ensure ALLOWED_URI_REGEXP is reset
  • Loading branch information
cure53 authored Apr 13, 2023
2 parents dcb9ebe + 1c63c4b commit 7fa8b97
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 18 deletions.
8 changes: 4 additions & 4 deletions dist/purify.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.cjs.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/purify.es.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.es.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/purify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/purify.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/purify.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/purify.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ function createDOMPurify(window = getGlobal()) {
SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
IN_PLACE = cfg.IN_PLACE || false; // Default false
IS_ALLOWED_URI = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
IS_ALLOWED_URI = cfg.ALLOWED_URI_REGEXP || EXPRESSIONS.IS_ALLOWED_URI;
NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
if (
Expand Down
18 changes: 18 additions & 0 deletions test/test-suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,21 @@
assert.equal(str, test.expected);
});
});
QUnit.test('Ensure ALLOWED_URI_REGEXP is not cached', function(assert) {
const
dirty = '<img src="https://different.com">',
expected = '<img src="https://different.com">';

assert.equal(DOMPurify.sanitize(dirty), expected);

// sanitize with a custom URI regexp
assert.equal(DOMPurify.sanitize('<img src="https://test.com">', {
ALLOWED_URI_REGEXP: /test\.com/i
}), '<img src="https://test.com">');

// ensure that the previous regexp does not affect future santize calls
assert.equal(DOMPurify.sanitize(dirty), expected);
});
QUnit.test(
'Avoid freeze when using tables and ALLOW_TAGS',
function (assert) {
Expand Down Expand Up @@ -2059,6 +2074,9 @@
// set the same hook
DOMPurify.addHook(entryPoint, hookFunction);
assert.equal(DOMPurify.sanitize(dirty), expected);

// cleanup hook
DOMPurify.removeHook(entryPoint);
});
};
});

0 comments on commit 7fa8b97

Please sign in to comment.