Skip to content

Commit

Permalink
fix: added a fix to handle invalid HTML Custom Element tagNames better
Browse files Browse the repository at this point in the history
  • Loading branch information
cure53 committed Mar 4, 2024
1 parent 1b59639 commit fcb9dbd
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 15 deletions.
9 changes: 6 additions & 3 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.

9 changes: 6 additions & 3 deletions dist/purify.es.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205
);

const DOCTYPE_NAME = seal(/^html$/i);
const CUSTOM_ELEMENT = seal(/^[a-z][a-z\d]*(-[a-z\d]+)+$/i);

var EXPRESSIONS = /*#__PURE__*/Object.freeze({
__proto__: null,
Expand All @@ -226,7 +227,8 @@ var EXPRESSIONS = /*#__PURE__*/Object.freeze({
IS_ALLOWED_URI: IS_ALLOWED_URI,
IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
ATTR_WHITESPACE: ATTR_WHITESPACE,
DOCTYPE_NAME: DOCTYPE_NAME
DOCTYPE_NAME: DOCTYPE_NAME,
CUSTOM_ELEMENT: CUSTOM_ELEMENT
});

const getGlobal = function getGlobal() {
Expand Down Expand Up @@ -351,7 +353,8 @@ function createDOMPurify() {
DATA_ATTR,
ARIA_ATTR,
IS_SCRIPT_OR_DATA,
ATTR_WHITESPACE
ATTR_WHITESPACE,
CUSTOM_ELEMENT
} = EXPRESSIONS;
let {
IS_ALLOWED_URI: IS_ALLOWED_URI$1
Expand Down Expand Up @@ -1088,7 +1091,7 @@ function createDOMPurify() {
* @returns {boolean} Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
*/
const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
return tagName !== 'annotation-xml' && tagName.indexOf('-') > 0;
return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion dist/purify.es.mjs.map

Large diffs are not rendered by default.

9 changes: 6 additions & 3 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.

3 changes: 2 additions & 1 deletion src/purify.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ function createDOMPurify(window = getGlobal()) {
ARIA_ATTR,
IS_SCRIPT_OR_DATA,
ATTR_WHITESPACE,
CUSTOM_ELEMENT,
} = EXPRESSIONS;

let { IS_ALLOWED_URI } = EXPRESSIONS;
Expand Down Expand Up @@ -1192,7 +1193,7 @@ function createDOMPurify(window = getGlobal()) {
* @returns {boolean} Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
*/
const _isBasicCustomElement = function (tagName) {
return tagName !== 'annotation-xml' && tagName.indexOf('-') > 0;
return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
};

/**
Expand Down
1 change: 1 addition & 0 deletions src/regexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export const ATTR_WHITESPACE = seal(
/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
);
export const DOCTYPE_NAME = seal(/^html$/i);
export const CUSTOM_ELEMENT = seal(/^[a-z][a-z\d]*(-[a-z\d]+)+$/i);

0 comments on commit fcb9dbd

Please sign in to comment.