-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Closed
Description
Right now the parseSearch and serializeSearch functions in utils use custom string parsing:
swagger-ui/src/core/utils/index.js
Lines 607 to 633 in 1a22b31
| export const parseSearch = () => { | |
| let map = {} | |
| let search = win.location.search | |
| if(!search) | |
| return {} | |
| if ( search != "" ) { | |
| let params = search.substr(1).split("&") | |
| for (let i in params) { | |
| if (!Object.prototype.hasOwnProperty.call(params, i)) { | |
| continue | |
| } | |
| i = params[i].split("=") | |
| map[decodeURIComponent(i[0])] = (i[1] && decodeURIComponent(i[1])) || "" | |
| } | |
| } | |
| return map | |
| } | |
| export const serializeSearch = (searchMap) => { | |
| return Object.keys(searchMap).map(k => { | |
| return encodeURIComponent(k) + "=" + encodeURIComponent(searchMap[k]) | |
| }).join("&") | |
| } |
Instead, we should move to using URLSearchParams which will make these functions compliant with the WHATWG specification.
The functions should be rewritten into:
export const parseSearch = () => {
const searchParams = new URLSearchParams(win.location.search)
return Object.fromEntries(searchParams)
}
export const serializeSearch = (searchMap) => {
const searchParams = new URLSearchParams(Object.entries(searchMap))
return String(searchParams)
}
Based on: #9722 (comment)