Skip to content

Commit a920096

Browse files
committed
Add ADD_FORBID_CONTENTS setting to extend default list
of FORBID_CONTENTS
1 parent ac64660 commit a920096

File tree

14 files changed

+75
-5
lines changed

14 files changed

+75
-5
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ const clean = DOMPurify.sanitize(dirty, {FORCE_BODY: true});
368368
// remove all <a> elements under <p> elements that are removed
369369
const clean = DOMPurify.sanitize(dirty, {FORBID_CONTENTS: ['a'], FORBID_TAGS: ['p']});
370370

371+
// extend the default FORBID_CONTENTS list to also remove <a> elements under <p> elements
372+
const clean = DOMPurify.sanitize(dirty, {ADD_FORBID_CONTENTS: ['a'], FORBID_TAGS: ['p']});
373+
371374
// change the parser type so sanitized data is treated as XML and not as HTML, which is the default
372375
const clean = DOMPurify.sanitize(dirty, {PARSER_MEDIA_TYPE: 'application/xhtml+xml'});
373376
```

dist/purify.cjs.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ interface Config {
9494
* Add child elements to be removed when their parent is removed.
9595
*/
9696
FORBID_CONTENTS?: string[] | undefined;
97+
/**
98+
* Extend the existing or default array of forbidden content elements.
99+
*/
100+
ADD_FORBID_CONTENTS?: string[] | undefined;
97101
/**
98102
* Add elements to block-list.
99103
*/

dist/purify.cjs.js

Lines changed: 6 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.d.mts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ interface Config {
9494
* Add child elements to be removed when their parent is removed.
9595
*/
9696
FORBID_CONTENTS?: string[] | undefined;
97+
/**
98+
* Extend the existing or default array of forbidden content elements.
99+
*/
100+
ADD_FORBID_CONTENTS?: string[] | undefined;
97101
/**
98102
* Add elements to block-list.
99103
*/

dist/purify.es.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,12 @@ function createDOMPurify() {
651651
}
652652
addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
653653
}
654+
if (cfg.ADD_FORBID_CONTENTS) {
655+
if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
656+
FORBID_CONTENTS = clone(FORBID_CONTENTS);
657+
}
658+
addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
659+
}
654660
/* Add #text in case KEEP_CONTENT is set to true */
655661
if (KEEP_CONTENT) {
656662
ALLOWED_TAGS['#text'] = true;

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: 6 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.

0 commit comments

Comments
 (0)