Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/bootstrap.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js/src/util
diff options
context:
space:
mode:
authorXhmikosR <xhmikosr@gmail.com>2021-09-15 14:34:24 +0300
committerGitHub <noreply@github.com>2021-09-15 14:34:24 +0300
commit8f2e6784241c8ca79ff84a7d8546a8b6b3b458bb (patch)
tree80a457c2608ba5bbe1e4e0b97ee5b0ae144f5830 /js/src/util
parentc5d03d93fca6288af8d2079d8fb80cd1c606ab52 (diff)
Minor refactoring (#34980)
Rename variables and remove a temporary one
Diffstat (limited to 'js/src/util')
-rw-r--r--js/src/util/focustrap.js6
-rw-r--r--js/src/util/sanitizer.js35
2 files changed, 18 insertions, 23 deletions
diff --git a/js/src/util/focustrap.js b/js/src/util/focustrap.js
index f1433c219f..d519422466 100644
--- a/js/src/util/focustrap.js
+++ b/js/src/util/focustrap.js
@@ -69,11 +69,7 @@ class FocusTrap {
const { target } = event
const { trapElement } = this._config
- if (
- target === document ||
- target === trapElement ||
- trapElement.contains(target)
- ) {
+ if (target === document || target === trapElement || trapElement.contains(target)) {
return
}
diff --git a/js/src/util/sanitizer.js b/js/src/util/sanitizer.js
index 467dbf96a0..11b28a9d9d 100644
--- a/js/src/util/sanitizer.js
+++ b/js/src/util/sanitizer.js
@@ -5,7 +5,7 @@
* --------------------------------------------------------------------------
*/
-const uriAttrs = new Set([
+const uriAttributes = new Set([
'background',
'cite',
'href',
@@ -32,22 +32,22 @@ const SAFE_URL_PATTERN = /^(?:(?:https?|mailto|ftp|tel|file):|[^#&/:?]*(?:[#/?]|
*/
const DATA_URL_PATTERN = /^data:(?:image\/(?:bmp|gif|jpeg|jpg|png|tiff|webp)|video\/(?:mpeg|mp4|ogg|webm)|audio\/(?:mp3|oga|ogg|opus));base64,[\d+/a-z]+=*$/i
-const allowedAttribute = (attr, allowedAttributeList) => {
- const attrName = attr.nodeName.toLowerCase()
+const allowedAttribute = (attribute, allowedAttributeList) => {
+ const attributeName = attribute.nodeName.toLowerCase()
- if (allowedAttributeList.includes(attrName)) {
- if (uriAttrs.has(attrName)) {
- return Boolean(SAFE_URL_PATTERN.test(attr.nodeValue) || DATA_URL_PATTERN.test(attr.nodeValue))
+ if (allowedAttributeList.includes(attributeName)) {
+ if (uriAttributes.has(attributeName)) {
+ return Boolean(SAFE_URL_PATTERN.test(attribute.nodeValue) || DATA_URL_PATTERN.test(attribute.nodeValue))
}
return true
}
- const regExp = allowedAttributeList.filter(attrRegex => attrRegex instanceof RegExp)
+ const regExp = allowedAttributeList.filter(attributeRegex => attributeRegex instanceof RegExp)
// Check if a regular expression validates the attribute.
for (let i = 0, len = regExp.length; i < len; i++) {
- if (regExp[i].test(attrName)) {
+ if (regExp[i].test(attributeName)) {
return true
}
}
@@ -100,25 +100,24 @@ export function sanitizeHtml(unsafeHtml, allowList, sanitizeFn) {
const domParser = new window.DOMParser()
const createdDocument = domParser.parseFromString(unsafeHtml, 'text/html')
- const allowlistKeys = Object.keys(allowList)
const elements = [].concat(...createdDocument.body.querySelectorAll('*'))
for (let i = 0, len = elements.length; i < len; i++) {
- const el = elements[i]
- const elName = el.nodeName.toLowerCase()
+ const element = elements[i]
+ const elementName = element.nodeName.toLowerCase()
- if (!allowlistKeys.includes(elName)) {
- el.remove()
+ if (!Object.keys(allowList).includes(elementName)) {
+ element.remove()
continue
}
- const attributeList = [].concat(...el.attributes)
- const allowedAttributes = [].concat(allowList['*'] || [], allowList[elName] || [])
+ const attributeList = [].concat(...element.attributes)
+ const allowedAttributes = [].concat(allowList['*'] || [], allowList[elementName] || [])
- attributeList.forEach(attr => {
- if (!allowedAttribute(attr, allowedAttributes)) {
- el.removeAttribute(attr.nodeName)
+ attributeList.forEach(attribute => {
+ if (!allowedAttribute(attribute, allowedAttributes)) {
+ element.removeAttribute(attribute.nodeName)
}
})
}