Skip to content

Commit

Permalink
Merge pull request #680 from tiny-ben-tran/performance-improvement
Browse files Browse the repository at this point in the history
Minor performance improvements
  • Loading branch information
cure53 committed May 11, 2022
2 parents e5931be + f4c5f80 commit 3d9dd14
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 52 deletions.
22 changes: 11 additions & 11 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.

22 changes: 11 additions & 11 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.

22 changes: 11 additions & 11 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.

29 changes: 15 additions & 14 deletions src/purify.js
Expand Up @@ -560,6 +560,18 @@ function createDOMPurify(window = getGlobal()) {
'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 Expand Up @@ -654,23 +666,11 @@ function createDOMPurify(window = getGlobal()) {
return false;
}

// 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 commonSvgAndHTMLElements = addToSet({}, [
'title',
'style',
'font',
'a',
'script',
]);

// We disallow tags that are specific for MathML
// or SVG and should never appear in HTML namespace
return (
!ALL_MATHML_TAGS[tagName] &&
(commonSvgAndHTMLElements[tagName] || !ALL_SVG_TAGS[tagName])
(COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName])
);
}

Expand Down Expand Up @@ -897,7 +897,7 @@ function createDOMPurify(window = getGlobal()) {
}

/* Check if tagname contains Unicode */
if (stringMatch(currentNode.nodeName, /[\u0080-\uFFFF]/)) {
if (regExpTest(/[\u0080-\uFFFF]/, currentNode.nodeName)) {
_forceRemove(currentNode);
return true;
}
Expand All @@ -913,6 +913,7 @@ function createDOMPurify(window = getGlobal()) {

/* Detect mXSS attempts abusing namespace confusion */
if (
currentNode.hasChildNodes() &&
!_isNode(currentNode.firstElementChild) &&
(!_isNode(currentNode.content) ||
!_isNode(currentNode.content.firstElementChild)) &&
Expand Down

0 comments on commit 3d9dd14

Please sign in to comment.