Skip to content

Commit

Permalink
pkg: lib: robustify self.path initialisation for cockpit.location
Browse files Browse the repository at this point in the history
Typescript reports an error for the original `[].concat(self.path)`,
self.path is initialised using this function so it can be undefined.

The code used to transparently work with undefined as `pop()` would drop
the undefined array item. To make this more robust however explicitly
handle `undefined` as this also helps with porting the code to
Typescript.
  • Loading branch information
jelly committed Nov 18, 2024
1 parent c34473a commit 2e2198d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/lib/cockpit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1166,8 +1166,8 @@ function factory() {
if (self.url_root)
pre_parts = self.url_root.split('/').map(decodeURIComponent);

if (input && input[0] !== "/") {
result = [].concat(self.path);
if (input && input[0] !== "/" && self.path !== undefined) {
result = [...self.path];
result.pop();
result = result.concat(parts);
} else {
Expand Down

0 comments on commit 2e2198d

Please sign in to comment.