From 2e2198d967b8e5905345d656b4dde25d3a939339 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Mon, 18 Nov 2024 13:56:44 +0100 Subject: [PATCH] pkg: lib: robustify self.path initialisation for cockpit.location 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. --- pkg/lib/cockpit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/lib/cockpit.js b/pkg/lib/cockpit.js index eb0e3453cd7..8d2d9e04ad8 100644 --- a/pkg/lib/cockpit.js +++ b/pkg/lib/cockpit.js @@ -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 {