From 59c206df34d65cb1549c183cfafea84651d38035 Mon Sep 17 00:00:00 2001 From: amoycode Date: Fri, 26 Jul 2024 07:03:13 +0000 Subject: [PATCH 1/2] refactor: Improve URL query parameter handling for correct concatenation and encoding --- packages/abc/lodop/lodop.service.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/abc/lodop/lodop.service.ts b/packages/abc/lodop/lodop.service.ts index e482dc9e5..fc61ecbdf 100644 --- a/packages/abc/lodop/lodop.service.ts +++ b/packages/abc/lodop/lodop.service.ts @@ -86,10 +86,18 @@ export class LodopService implements OnDestroy { if (!this._lodop) throw new Error(`请务必先调用 lodop 获取对象`); } + private requestUrl(): string { + const urlObj = new URL(this.cog.url!); + const params = new URLSearchParams(urlObj.search); + params.set('name', this.cog.name!); + urlObj.search = params.toString(); + return urlObj.toString(); + } + private request(): void { this.pending = true; - const url = `${this.cog.url}?name=${this.cog.name}`; + const url = this.requestUrl(); let checkMaxCount = this.cog.checkMaxCount as number; const onResolve = (status: NzSafeAny, error?: NzSafeAny): void => { this._init.next({ @@ -160,7 +168,7 @@ export class LodopService implements OnDestroy { try { const fakeFn = new Function(`return [${res[2]}]`); arr = fakeFn(); - } catch {} + } catch { } if (arr != null && Array.isArray(arr) && contextObj) { for (let i = 0; i < arr.length; i++) { From 790dfa3f98c0eb1e832daba52c00babb734a3c2f Mon Sep 17 00:00:00 2001 From: amoycode Date: Sun, 28 Jul 2024 09:00:39 +0000 Subject: [PATCH 2/2] construct 'URL': Invalid URL --- packages/abc/lodop/lodop.service.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/abc/lodop/lodop.service.ts b/packages/abc/lodop/lodop.service.ts index fc61ecbdf..0b16d2432 100644 --- a/packages/abc/lodop/lodop.service.ts +++ b/packages/abc/lodop/lodop.service.ts @@ -87,9 +87,15 @@ export class LodopService implements OnDestroy { } private requestUrl(): string { - const urlObj = new URL(this.cog.url!); + if (!this.cog.url) { + throw new Error('URL is not defined'); + } + if (!this.cog.name) { + throw new Error('Name is not defined'); + } + const urlObj = new URL(this.cog.url); const params = new URLSearchParams(urlObj.search); - params.set('name', this.cog.name!); + params.set('name', this.cog.name); urlObj.search = params.toString(); return urlObj.toString(); }