Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Do not use optional chaining on a potentially undeclared root object
The global "OC" variable may be undefined depending on the
initialization order, so optional chaining ("OC?.config" and
"OC?.debug") was added to prevent accessing fields on an undefined
variable.

However, "OC" could be not only undefined, but also undeclared. Optional
chaining can not be used on an undeclared root object, so it needs to be
explicitly guarded against that to prevent a ReferenceError to be
thrown.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu committed Aug 18, 2022
commit 04a49318cbca9963e2a33c960836eca3c7f5a655
4 changes: 2 additions & 2 deletions lib/LoggerBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export class LoggerBuilder {
this.context = {}
this.factory = factory
// Up to, including, nextcloud 24 the loglevel was not exposed
this.context.level = OC?.config?.loglevel !== undefined ? OC.config.loglevel : LogLevel.Warn
this.context.level = (window.hasOwnProperty('OC') && OC?.config?.loglevel !== undefined) ? OC.config.loglevel : LogLevel.Warn
// Override loglevel if we are in debug mode
if (OC?.debug) {
if (window.hasOwnProperty('OC') && OC?.debug) {
this.context.level = LogLevel.Debug
}
}
Expand Down