Skip to content

Commit c69d7a8

Browse files
authored
Merge pull request #1080 from hhk-png/main
fix: Using ALLOWED_URI_REGEXP with the 'g' flag leads to incorrect result
2 parents b428788 + fce40b5 commit c69d7a8

File tree

10 files changed

+31
-6
lines changed

10 files changed

+31
-6
lines changed

dist/purify.cjs.js

Lines changed: 3 additions & 0 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.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ const typeErrorCreate = unconstruct(TypeError);
5858
*/
5959
function unapply(func) {
6060
return function (thisArg) {
61+
if (thisArg instanceof RegExp) {
62+
thisArg.lastIndex = 0;
63+
}
6164
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
6265
args[_key - 1] = arguments[_key];
6366
}

dist/purify.es.mjs.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 & 0 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/utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ const typeErrorCreate = unconstruct(TypeError);
6363
function unapply<T>(
6464
func: (thisArg: any, ...args: any[]) => T
6565
): (thisArg: any, ...args: any[]) => T {
66-
return (thisArg: any, ...args: any[]): T => apply(func, thisArg, args);
66+
return (thisArg: any, ...args: any[]): T => {
67+
if (thisArg instanceof RegExp) {
68+
thisArg.lastIndex = 0;
69+
}
70+
71+
return apply(func, thisArg, args);
72+
};
6773
}
6874

6975
/**

test/test-suite.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,5 +2193,15 @@
21932193
let clean = DOMPurify.sanitize(dirty, config);
21942194
assert.contains(clean, expected);
21952195
});
2196+
2197+
QUnit.test('Expect the same results when using ALLOWED_URI_REGEXP with the g flag', function (assert) {
2198+
const dirty = '<img src="blob:http://localhost:5173/84c49be9-3352-4407-b066-7b5b4d46c52a"><a epub:type="noteref" href="epub:EPUB/xhtml/#footnote"></a><img src="blob:http://localhost:5173/84c49be9-3352-4407" >';
2199+
const config = {
2200+
ALLOWED_URI_REGEXP: /^(blob|https|epub|filepos|kindle)/gi,
2201+
};
2202+
const expected = '<img src=\"blob:http://localhost:5173/84c49be9-3352-4407-b066-7b5b4d46c52a\"><a href=\"epub:EPUB/xhtml/#footnote\"></a><img src=\"blob:http://localhost:5173/84c49be9-3352-4407\">';
2203+
let clean = DOMPurify.sanitize(dirty, config);
2204+
assert.strictEqual(clean, expected);
2205+
});
21962206
};
21972207
});

0 commit comments

Comments
 (0)