-
-
Notifications
You must be signed in to change notification settings - Fork 726
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
refac(purify): Refactoring purify #849
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1068,9 +1068,11 @@ function createDOMPurify(window = getGlobal()) { | |
if (SAFE_FOR_TEMPLATES && currentNode.nodeType === 3) { | ||
/* Get the element's text content */ | ||
content = currentNode.textContent; | ||
content = stringReplace(content, MUSTACHE_EXPR, ' '); | ||
content = stringReplace(content, ERB_EXPR, ' '); | ||
content = stringReplace(content, TMPLIT_EXPR, ' '); | ||
|
||
arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], (expr) => { | ||
content = stringReplace(content, expr, ' '); | ||
}); | ||
|
||
if (currentNode.textContent !== content) { | ||
arrayPush(DOMPurify.removed, { element: currentNode.cloneNode() }); | ||
currentNode.textContent = content; | ||
|
@@ -1202,10 +1204,6 @@ function createDOMPurify(window = getGlobal()) { | |
* @param {Node} currentNode to sanitize | ||
*/ | ||
const _sanitizeAttributes = function (currentNode) { | ||
let attr = null; | ||
let value = null; | ||
let lcName = null; | ||
let l = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion, moving the variables inside the "while" block would make the code more predictable. |
||
/* Execute a hook if present */ | ||
_executeHook('beforeSanitizeAttributes', currentNode, null); | ||
|
||
|
@@ -1222,14 +1220,15 @@ function createDOMPurify(window = getGlobal()) { | |
keepAttr: true, | ||
allowedAttributes: ALLOWED_ATTR, | ||
}; | ||
l = attributes.length; | ||
let l = attributes.length; | ||
|
||
/* Go backwards over all attributes; safely remove bad ones */ | ||
while (l--) { | ||
attr = attributes[l]; | ||
const attr = attributes[l]; | ||
const { name, namespaceURI, value: attrValue } = attr; | ||
value = name === 'value' ? attrValue : stringTrim(attrValue); | ||
lcName = transformCaseFunc(name); | ||
const lcName = transformCaseFunc(name); | ||
|
||
let value = name === 'value' ? attrValue : stringTrim(attrValue); | ||
|
||
/* Execute a hook if present */ | ||
hookEvent.attrName = lcName; | ||
|
@@ -1259,9 +1258,9 @@ function createDOMPurify(window = getGlobal()) { | |
|
||
/* Sanitize attribute content to be template-safe */ | ||
if (SAFE_FOR_TEMPLATES) { | ||
value = stringReplace(value, MUSTACHE_EXPR, ' '); | ||
value = stringReplace(value, ERB_EXPR, ' '); | ||
value = stringReplace(value, TMPLIT_EXPR, ' '); | ||
arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], (expr) => { | ||
value = stringReplace(value, expr, ' '); | ||
}); | ||
} | ||
|
||
/* Is `value` valid for this attribute? */ | ||
|
@@ -1530,9 +1529,9 @@ function createDOMPurify(window = getGlobal()) { | |
|
||
/* Sanitize final string template-safe */ | ||
if (SAFE_FOR_TEMPLATES) { | ||
serializedHTML = stringReplace(serializedHTML, MUSTACHE_EXPR, ' '); | ||
serializedHTML = stringReplace(serializedHTML, ERB_EXPR, ' '); | ||
serializedHTML = stringReplace(serializedHTML, TMPLIT_EXPR, ' '); | ||
arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], (expr) => { | ||
serializedHTML = stringReplace(serializedHTML, expr, ' '); | ||
}); | ||
} | ||
|
||
return trustedTypesPolicy && RETURN_TRUSTED_TYPE | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a love/hate thing. I think your thoughts will be important. 😂 @cure53
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it 🙂