Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parseQueryString #18

Closed
makebanana opened this issue Dec 18, 2017 · 3 comments
Closed

parseQueryString #18

makebanana opened this issue Dec 18, 2017 · 3 comments

Comments

@makebanana
Copy link

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

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

@proYang
Copy link
Owner

proYang commented Dec 22, 2017

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

@proYang proYang added the 疑问 label Dec 22, 2017
@makebanana
Copy link
Author

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

@proYang
Copy link
Owner

proYang commented Dec 24, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants