From f952abc95a515b95d67c67742501515559c2590c Mon Sep 17 00:00:00 2001 From: ztimson Date: Sun, 13 Apr 2025 09:50:19 -0400 Subject: [PATCH] More zelous path fixing in the http client --- package.json | 2 +- src/http.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index dbe7d03..e43ab3b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ztimson/utils", - "version": "0.23.20", + "version": "0.23.21", "description": "Utility library", "author": "Zak Timson", "license": "MIT", diff --git a/src/http.ts b/src/http.ts index 80f3ae4..ffd65f9 100644 --- a/src/http.ts +++ b/src/http.ts @@ -70,8 +70,9 @@ export class Http { request(opts: HttpRequestOptions = {}): PromiseProgress> { if(!this.url && !opts.url) throw new Error('URL needs to be set'); - let url = (opts.url?.startsWith('http') ? opts.url : (this.url || '') + (opts.url || '')).replace(/([^:]\/)\/+/g, '$1'); - if(opts.fragment) url.includes('#') ? url.replace(/#.*(\?|\n)/g, (match, arg1) => `#${opts.fragment}${arg1}`) : url += '#' + opts.fragment; + let url = opts.url?.startsWith('http') ? opts.url : (this.url || '') + (opts.url || ''); + url = url.replaceAll(/([^:]\/)\/+/g, '$1'); + if(opts.fragment) url.includes('#') ? url.replace(/#.*(\?|\n)/g, (match, arg1) => `#${opts.fragment}${arg1}`) : `${url}#${opts.fragment}`; if(opts.query) { const q = Array.isArray(opts.query) ? opts.query : Object.keys(opts.query).map(k => ({key: k, value: (opts.query)[k]}))