Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions templates/base/http-clients/fetch-http-client.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,22 @@ export class HttpClient<SecurityDataType = unknown> {
}

protected addArrayQueryParam(query: QueryParamsType, key: string) {
const value = query[key];
return value.map((v: any) => this.encodeQueryParam(key, v)).join("&");
const value = Array.isArray(query[key])
? query[key].map((value, index) => [index, value])
: Object.entries(query[key]);
return value.map(([arrayKey, value]: any) => this.encodeQueryParam(`${key}[${arrayKey}]`, value)).join("&");
}

protected toQueryString(rawQuery?: QueryParamsType): string {
const query = rawQuery || {};
const keys = Object.keys(query).filter((key) => "undefined" !== typeof query[key]);
return keys
.map((key) =>
Array.isArray(query[key])
? this.addArrayQueryParam(query, key)
: this.addQueryParam(query, key),
)
.join("&");
.map((key) =>
typeof query[key] === "object" || Array.isArray(query[key])
? this.addArrayQueryParam(query, key)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Null Handling Error in Query String Method

The toQueryString method incorrectly treats null values as objects, causing addArrayQueryParam to receive null. This results in a TypeError when Object.entries(null) is called.

Fix in Cursor Fix in Web

: this.addQueryParam(query, key),
)
.join("&");
}

protected addQueryParams(rawQuery?: QueryParamsType): string {
Expand Down
Loading