Describe the bug
In the makeUrl utility function (frontend/src/lib/k8s/api/v2/makeUrl.ts and similarly in v1/formatUrl.ts), the query parameters object is passed directly to new URLSearchParams(query).toString().
If a query parameter is explicitly passed as undefined (e.g., { watch: '1', fieldSelector: undefined }), URLSearchParams converts the undefined value into the literal string "undefined". The resulting query string becomes ?watch=1&fieldSelector=undefined. When this request is sent to the Kubernetes API, it attempts to parse "undefined" as a valid field selector, resulting in API rejection or unexpected behavior.
Steps to Reproduce
- Make a request to the Kubernetes API using a client helper that conditionally passes
undefined for optional parameters (like fieldSelector or labelSelector).
- Inspect the outgoing network request URL.
- Notice that the URL query string contains
&fieldSelector=undefined instead of omitting the key entirely.
- Observe the Kubernetes API rejecting the request with an error about invalid selector syntax.
Expected behavior
The makeUrl function should filter out undefined or null values from the query object before converting them into a query string, effectively omitting the keys so the URL remains clean and valid.
Suggested Fix
In both frontend/src/lib/k8s/api/v2/makeUrl.ts (around line 39) and frontend/src/lib/k8s/api/v1/formatUrl.ts (around line 68), filter the query object before passing it to URLSearchParams:
const cleanQuery = Object.fromEntries(
Object.entries(query).filter(([, v]) => v !== undefined && v !== null)
);
const queryString = new URLSearchParams(cleanQuery).toString();
Describe the bug
In the
makeUrlutility function (frontend/src/lib/k8s/api/v2/makeUrl.tsand similarly inv1/formatUrl.ts), the query parameters object is passed directly tonew URLSearchParams(query).toString().If a query parameter is explicitly passed as
undefined(e.g.,{ watch: '1', fieldSelector: undefined }),URLSearchParamsconverts theundefinedvalue into the literal string"undefined". The resulting query string becomes?watch=1&fieldSelector=undefined. When this request is sent to the Kubernetes API, it attempts to parse"undefined"as a valid field selector, resulting in API rejection or unexpected behavior.Steps to Reproduce
undefinedfor optional parameters (likefieldSelectororlabelSelector).&fieldSelector=undefinedinstead of omitting the key entirely.Expected behavior
The
makeUrlfunction should filter outundefinedornullvalues from the query object before converting them into a query string, effectively omitting the keys so the URL remains clean and valid.Suggested Fix
In both
frontend/src/lib/k8s/api/v2/makeUrl.ts(around line 39) andfrontend/src/lib/k8s/api/v1/formatUrl.ts(around line 68), filter the query object before passing it toURLSearchParams: