@f5xc-salesdemos/pi-utils 19.45.0 → 19.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@f5xc-salesdemos/pi-utils",
4
- "version": "19.45.0",
4
+ "version": "19.46.0",
5
5
  "description": "Shared utilities for pi packages",
6
6
  "homepage": "https://github.com/f5xc-salesdemos/xcsh",
7
7
  "author": "Can Boluk",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/bun": "^1.3",
42
- "@f5xc-salesdemos/pi-natives": "19.45.0"
42
+ "@f5xc-salesdemos/pi-natives": "19.46.0"
43
43
  },
44
44
  "engines": {
45
45
  "bun": ">=1.3.7"
@@ -163,17 +163,28 @@ export function isSafeContextName(name: string): boolean {
163
163
  }
164
164
 
165
165
  /**
166
- * Normalize an API URL for safe path joining by stripping trailing slash(es).
166
+ * Normalize an API URL to its origin (`https://host[:port]`) the canonical
167
+ * stored form for a context endpoint, shared verbatim by the xcsh shell and the
168
+ * VS Code extension.
167
169
  *
168
- * The shared resource library joins URLs by raw concatenation
169
- * (`${apiUrl}${path}`) where path templates begin with `/api/...`. A trailing
170
- * slash produces `https://host/api//api/...`; after the transport strips the
171
- * base URL the remainder begins with `//`, which `new URL()` parses as a
172
- * protocol-relative authority collapsing the host to a bare label and breaking
173
- * TLS altname verification. Stripping trailing slashes prevents this.
170
+ * The stored value must be the bare origin only: no path, query, fragment, or
171
+ * trailing slash. Callers append `/api/...` themselves, so the endpoint stays a
172
+ * single consistent value. This also defuses the protocol-relative host
173
+ * collapse: the shared resource library joins URLs by raw concatenation
174
+ * (`${apiUrl}${path}`), and a leftover path or trailing slash would produce a
175
+ * `//` that `new URL()` parses as an authority — collapsing the host to a bare
176
+ * label and breaking TLS altname verification.
174
177
  */
175
178
  export function normalizeApiUrl(apiUrl: string): string {
176
- return typeof apiUrl === "string" ? apiUrl.replace(/\/+$/, "") : apiUrl;
179
+ if (typeof apiUrl !== "string") return apiUrl;
180
+ const trimmed = apiUrl.trim();
181
+ try {
182
+ return new URL(trimmed).origin;
183
+ } catch {
184
+ // Not a parseable absolute URL (input validation should prevent this);
185
+ // fall back to stripping trailing slashes so we never worsen a bad value.
186
+ return trimmed.replace(/\/+$/, "");
187
+ }
177
188
  }
178
189
 
179
190
  function defaultGitTracker(filePath: string): Promise<boolean> {