Skip to content

Commit

Permalink
see #1022
Browse files Browse the repository at this point in the history
feature: Added configurability for text & HTML integration points
  • Loading branch information
cure53 committed Oct 11, 2024
1 parent 785982c commit e4caa67
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 51 deletions.
18 changes: 10 additions & 8 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.

18 changes: 10 additions & 8 deletions dist/purify.es.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,14 @@ function createDOMPurify() {
/* Allowed XHTML+XML namespaces */
let ALLOWED_NAMESPACES = null;
const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);

// Certain elements are allowed in both SVG and HTML
// namespace. We need to specify them explicitly
// so that they don't get erroneously deleted from
// HTML namespace.
const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);

/* Parsing of strict XHTML documents */
let PARSER_MEDIA_TYPE = null;
Expand Down Expand Up @@ -604,6 +612,8 @@ function createDOMPurify() {
IN_PLACE = cfg.IN_PLACE || false; // Default false
IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
Expand Down Expand Up @@ -716,14 +726,6 @@ function createDOMPurify() {
}
CONFIG = cfg;
};
const MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
const HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);

// Certain elements are allowed in both SVG and HTML
// namespace. We need to specify them explicitly
// so that they don't get erroneously deleted from
// HTML namespace.
const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);

/* Keep track of all possible SVG and MathML tags
* so that we can perform the namespace checks
Expand Down
2 changes: 1 addition & 1 deletion dist/purify.es.mjs.map

Large diffs are not rendered by default.

18 changes: 10 additions & 8 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.

49 changes: 27 additions & 22 deletions src/purify.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,28 @@ function createDOMPurify(window = getGlobal()) {
stringToString
);

let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, [
'mi',
'mo',
'mn',
'ms',
'mtext',
]);

let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);

// Certain elements are allowed in both SVG and HTML
// namespace. We need to specify them explicitly
// so that they don't get erroneously deleted from
// HTML namespace.
const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, [
'title',
'style',
'font',
'a',
'script',
]);

/* Parsing of strict XHTML documents */
let PARSER_MEDIA_TYPE = null;
const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
Expand Down Expand Up @@ -502,6 +524,11 @@ function createDOMPurify(window = getGlobal()) {
IN_PLACE = cfg.IN_PLACE || false; // Default false
IS_ALLOWED_URI = cfg.ALLOWED_URI_REGEXP || EXPRESSIONS.IS_ALLOWED_URI;
NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
MATHML_TEXT_INTEGRATION_POINTS =
cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
HTML_INTEGRATION_POINTS =
cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;

CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || {};
if (
cfg.CUSTOM_ELEMENT_HANDLING &&
Expand Down Expand Up @@ -651,28 +678,6 @@ function createDOMPurify(window = getGlobal()) {
CONFIG = cfg;
};

const MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, [
'mi',
'mo',
'mn',
'ms',
'mtext',
]);

const HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);

// Certain elements are allowed in both SVG and HTML
// namespace. We need to specify them explicitly
// so that they don't get erroneously deleted from
// HTML namespace.
const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, [
'title',
'style',
'font',
'a',
'script',
]);

/* Keep track of all possible SVG and MathML tags
* so that we can perform the namespace checks
* correctly. */
Expand Down

0 comments on commit e4caa67

Please sign in to comment.