mirror of
https://github.com/electron/node-gyp.git
synced 2025-08-15 12:58:19 +02:00
Fix isVisible() so that all log levels won't get printed all the time
Log level `silly` is getting output which outputs all env vars which is a bit dodgy - it will eventually leak secrets if users aren't cautious. `(this.level && this.level.index <= (this.#levels.get(level) && this.#levels.get(level).index) || -1)` simplifies to `(a && b || -1)` which is always truthy. Furthermore I think the || -1 would have turned log lines of index 0's index into -1 so they would never match once the parenthesis is fixed. (Why not use the ?? operator?) I think this is just easier to reason about and to get right if you check for null/undefined up front where you expect objects and then early return. Then you can't turn 0 into -1 accidentally and it reads much more easily.
This commit is contained in:
parent
0453f4fe46
commit
3ec23c5348
1 changed files with 5 additions and 1 deletions
|
@ -97,7 +97,11 @@ class Logger {
|
||||||
}
|
}
|
||||||
|
|
||||||
isVisible (level) {
|
isVisible (level) {
|
||||||
return (this.level && this.level.index <= (this.#levels.get(level) && this.#levels.get(level).index) || -1)
|
if (!this.level || !this.#levels.get(level)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.level.index <= this.#levels.get(level).index
|
||||||
}
|
}
|
||||||
|
|
||||||
_onLog (...args) {
|
_onLog (...args) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue