Closed oscaramos closed 1 year ago
The extractQueryParameters function may not be returning all query parameters in scenarios where a parameter value contains a question mark (?).
For a demonstration, please refer to and execute the code provided here.
export function extractQueryParameters(request: { url: string }): Record<string, any> { const url = decodeURIComponent(request.url).split('?') if (url.length === 1) { return {} } const query = url[1] const params: Record<string, any> = {} for (const param of query.split('&')) { const paramSplitted = param.split('=') const key = paramSplitted[0] const value = paramSplitted[1] if (params[key] === undefined) { params[key] = value } else if (!Array.isArray(params[key])) { params[key] = [params[key], value] } else { params[key].push(value) } } return params } const baseURL = "http://example.com?" const passingCase = baseURL + encodeURIComponent("question=What is the answer to life, the universe and everything&answer=42") const failingCase = baseURL + encodeURIComponent("question=What is the answer to life, the universe and everything?&answer=42") console.log("URLs") console.log("Passing case url: ", passingCase) console.log("Failing case url: ", failingCase) console.log("\nQuery Parameters") console.log("Passing: ", extractQueryParameters({ url: passingCase })) console.log("Failing: ", extractQueryParameters({ url: failingCase }))
Hey @oscaramos thanks for contributing this fix Your changes been bundled in the latest release (v0.1.4)
The extractQueryParameters function may not be returning all query parameters in scenarios where a parameter value contains a question mark (?).
For a demonstration, please refer to and execute the code provided here.