Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(purify): fix _createIterator #850

Merged
merged 5 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 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.

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

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

16 changes: 8 additions & 8 deletions src/purify.js
Original file line number Diff line number Diff line change
Expand Up @@ -900,19 +900,18 @@ function createDOMPurify(window = getGlobal()) {
};

/**
* _createIterator
* Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
*
* @param {Document} root document/fragment to create iterator for
* @return {Iterator} iterator instance
* @param {Node} root The root element or node to start traversing on.
* @return {NodeIterator} The created NodeIterator
*/
const _createIterator = function (root) {
const _createNodeIterator = function (root) {
Comment on lines +903 to +908
Copy link
Contributor Author

@ssi02014 ssi02014 Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/microsoft/TypeScript/blob/main/src/lib/dom.generated.d.ts#L7160
I've modified the jsdoc with reference to that documentation.

Also, the naming seems clearer for _createNodeIterator than _createIterator. (Returns a NodeIterator.)
What do you think of this fix? 🙏

return createNodeIterator.call(
root.ownerDocument || root,
root,
// eslint-disable-next-line no-bitwise
NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT,
null,
false
null
Comment on lines -915 to +914
Copy link
Contributor Author

@ssi02014 ssi02014 Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed that argument. ("false")

);
};

Expand Down Expand Up @@ -1188,6 +1187,7 @@ function createDOMPurify(window = getGlobal()) {
* for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
*
* @param {string} tagName name of the tag of the node to sanitize
* @returns {boolean} Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
*/
const _basicCustomElementTest = function (tagName) {
return tagName.indexOf('-') > 0;
Expand Down Expand Up @@ -1331,7 +1331,7 @@ function createDOMPurify(window = getGlobal()) {
*/
const _sanitizeShadowDOM = function (fragment) {
let shadowNode = null;
const shadowIterator = _createIterator(fragment);
const shadowIterator = _createNodeIterator(fragment);

/* Execute a hook if present */
_executeHook('beforeSanitizeShadowDOM', fragment, null);
Expand Down Expand Up @@ -1462,7 +1462,7 @@ function createDOMPurify(window = getGlobal()) {
}

/* Get node iterator */
const nodeIterator = _createIterator(IN_PLACE ? dirty : body);
const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);

/* Now start iterating over the created document */
while ((currentNode = nodeIterator.nextNode())) {
Expand Down