Skip to content

Commit fcb9dbd

Browse files
committedMar 4, 2024··
fix: added a fix to handle invalid HTML Custom Element tagNames better
1 parent 1b59639 commit fcb9dbd

10 files changed

+26
-15
lines changed
 

‎dist/purify.cjs.js

+6-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.cjs.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.es.mjs

+6-3
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205
215215
);
216216

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

219220
var EXPRESSIONS = /*#__PURE__*/Object.freeze({
220221
__proto__: null,
@@ -226,7 +227,8 @@ var EXPRESSIONS = /*#__PURE__*/Object.freeze({
226227
IS_ALLOWED_URI: IS_ALLOWED_URI,
227228
IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
228229
ATTR_WHITESPACE: ATTR_WHITESPACE,
229-
DOCTYPE_NAME: DOCTYPE_NAME
230+
DOCTYPE_NAME: DOCTYPE_NAME,
231+
CUSTOM_ELEMENT: CUSTOM_ELEMENT
230232
});
231233

232234
const getGlobal = function getGlobal() {
@@ -351,7 +353,8 @@ function createDOMPurify() {
351353
DATA_ATTR,
352354
ARIA_ATTR,
353355
IS_SCRIPT_OR_DATA,
354-
ATTR_WHITESPACE
356+
ATTR_WHITESPACE,
357+
CUSTOM_ELEMENT
355358
} = EXPRESSIONS;
356359
let {
357360
IS_ALLOWED_URI: IS_ALLOWED_URI$1
@@ -1088,7 +1091,7 @@ function createDOMPurify() {
10881091
* @returns {boolean} Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
10891092
*/
10901093
const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
1091-
return tagName !== 'annotation-xml' && tagName.indexOf('-') > 0;
1094+
return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
10921095
};
10931096

10941097
/**

‎dist/purify.es.mjs.map

+1-1
Large diffs are not rendered by default.

‎dist/purify.js

+6-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/purify.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/purify.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ function createDOMPurify(window = getGlobal()) {
162162
ARIA_ATTR,
163163
IS_SCRIPT_OR_DATA,
164164
ATTR_WHITESPACE,
165+
CUSTOM_ELEMENT,
165166
} = EXPRESSIONS;
166167

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

11981199
/**

‎src/regexp.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ export const ATTR_WHITESPACE = seal(
1414
/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
1515
);
1616
export const DOCTYPE_NAME = seal(/^html$/i);
17+
export const CUSTOM_ELEMENT = seal(/^[a-z][a-z\d]*(-[a-z\d]+)+$/i);

0 commit comments

Comments
 (0)
Please sign in to comment.