proYang / outils

:rocket: 前端业务代码工具库
https://www.npmjs.com/package/outils
MIT License
2.61k stars 591 forks source link

parseQueryString #18

Closed makebanana closed 6 years ago

makebanana commented 6 years ago

return JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}')

decodeURIComponent 过早了吧, & , = 特殊字符 JSON.parse 之后 枚举处理吧

proYang commented 6 years ago

这里replace的本意,是将解码后的url查询字符串中的&=等特殊字符串替换,拼接成一个类似的JSON字符串,然后再通过JSON.parse()方法转换为一个参数对象,不存在上述问题。

makebanana commented 6 years ago

encodeURIComponent('&') = '%26' parseQueryString('www.baidu.com?a=123&b=%26') make try

proYang commented 6 years ago

:rose: 感谢你的细心,已在最新版本中更正了这个错误。