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

Use regex.test() when we want to check for a Boolean. #29969

Merged
merged 2 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion build/vnu-jar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion js/src/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 2 additions & 3 deletions js/src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

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

tabClass.length is equal too tabClass.length > 0 not really needed that change

Copy link
Member Author

@XhmikosR XhmikosR Jan 7, 2020

Choose a reason for hiding this comment

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

It's what we do in popover.js; this code is exactly the same

Copy link
Member

Choose a reason for hiding this comment

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

So we can change that in popover.js too 😄 but it's nitpicking

Copy link
Member Author

Choose a reason for hiding this comment

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

Fine by me, I'd just prefer if we enforced this with a rule, but I cannot find one, only for the opposite unicorn/explicit-length-check

tabClass.map(token => token.trim())
.forEach(tClass => tip.classList.remove(tClass))
}
}
Expand Down
6 changes: 3 additions & 3 deletions js/src/util/sanitizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
Expand Down