From f7abfe296c44daadb18c179f7c304ab271fd7c37 Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sun, 5 Jan 2020 15:27:28 +0200 Subject: [PATCH] Use regex.test() when we want to check for a Boolean. --- build/vnu-jar.js | 2 +- js/src/popover.js | 1 - js/src/tooltip.js | 5 ++--- js/src/util/sanitizer.js | 6 +++--- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/build/vnu-jar.js b/build/vnu-jar.js index 53fc58636f8d..4018873f8dcd 100644 --- a/build/vnu-jar.js +++ b/build/vnu-jar.js @@ -18,7 +18,7 @@ childProcess.exec('java -version', (error, stdout, stderr) => { return } - const is32bitJava = !stderr.match(/64-Bit/) + const is32bitJava = !/64-Bit/.test(stderr) // vnu-jar accepts multiple ignores joined with a `|`. // Also note that the ignores are regular expressions. diff --git a/js/src/popover.js b/js/src/popover.js index a633af4ba0b9..d71a78236cd4 100644 --- a/js/src/popover.js +++ b/js/src/popover.js @@ -135,7 +135,6 @@ class Popover extends Tooltip { _cleanTipClass() { const tip = this.getTipElement() const tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX) - if (tabClass !== null && tabClass.length > 0) { tabClass.map(token => token.trim()) .forEach(tClass => tip.classList.remove(tClass)) diff --git a/js/src/tooltip.js b/js/src/tooltip.js index b4f047b70ef2..1bc000d2ccc7 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -747,9 +747,8 @@ class Tooltip { _cleanTipClass() { const tip = this.getTipElement() const tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX) - if (tabClass !== null && tabClass.length) { - tabClass - .map(token => token.trim()) + if (tabClass !== null && tabClass.length > 0) { + tabClass.map(token => token.trim()) .forEach(tClass => tip.classList.remove(tClass)) } } diff --git a/js/src/util/sanitizer.js b/js/src/util/sanitizer.js index a85bc5f91d0e..8f72d2005af0 100644 --- a/js/src/util/sanitizer.js +++ b/js/src/util/sanitizer.js @@ -39,7 +39,7 @@ const allowedAttribute = (attr, allowedAttributeList) => { if (allowedAttributeList.indexOf(attrName) !== -1) { if (uriAttrs.indexOf(attrName) !== -1) { - return Boolean(attr.nodeValue.match(SAFE_URL_PATTERN) || attr.nodeValue.match(DATA_URL_PATTERN)) + return SAFE_URL_PATTERN.test(attr.nodeValue) || DATA_URL_PATTERN.test(attr.nodeValue) } return true @@ -48,8 +48,8 @@ const allowedAttribute = (attr, allowedAttributeList) => { const regExp = allowedAttributeList.filter(attrRegex => attrRegex instanceof RegExp) // Check if a regular expression validates the attribute. - for (let i = 0, l = regExp.length; i < l; i++) { - if (attrName.match(regExp[i])) { + for (let i = 0, len = regExp.length; i < len; i++) { + if (regExp[i].test(attrName)) { return true } }