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

reuse searchParams #9

Closed
zh99998 opened this issue Sep 4, 2017 · 4 comments
Closed

reuse searchParams #9

zh99998 opened this issue Sep 4, 2017 · 4 comments

Comments

@zh99998
Copy link
Contributor

zh99998 commented Sep 4, 2017

currently every time get searchParams will create a new object, which is waste memory and cause problem.
currently, in chrome 49.

const url = new URL('http://example.com/?a=1');
url.searchParams.set('b','2')
url.searchParams.set('c','3')
console.log(url.toString())

=>

http://example.com/?%3F%3Fa=1&b=2&c=3

will get some mysterious %3F in search string, seems it's caused by duplicated searchParams create.


btw, chrome 49 support both URL and URLSearchParams, but no url.searchParams.
this may help you debug.


well no i guess wrong.
only one searchParams call will cause this problem too.

const url = new URL('http://example.com/?a=1');
const params = url.searchParams;
params.set('b','2');
params.set('c','3');
console.log(url.toString())

=>

http://example.com/?%3Fa=1&b=2&c=3

I found that.

this version of chrome native URLSearchParams doesn't cut leading ?

in chrome 49

new URLSearchParams('?a=1').toString() #=> "%3Fa=1"

in chrome 60

new URLSearchParams('?a=1').toString() #=> "a=1"

seems these should be more check before using native URLSearchParams, like

  if(!('URLSearchParams' in global && new URLSearchParams('?a=1').toString() === 'a=1')) {
    polyfillURLSearchParams();
  }
@lifaon74
Copy link
Owner

lifaon74 commented Sep 4, 2017

Well, I haven't a chrome 49 version. Could you check what native code exists on URL/URLSearchParams for chrome 49 ? Or even do a pull request if you find a fix ?
This polyfill is intended to be lightweight, so it use the maximum of native functions. Some could be errored. For example, on the last version of chrome (60~62) the URL is not spec compliant because the hash is not url-escaped... But this still covers 99.9% of the usage.

@lifaon74
Copy link
Owner

lifaon74 commented Sep 4, 2017

Could you please provide methe result of new URLSearchParams('?a=1').toString() on chrome 49 without polyfill.

I can't accept right now your pull request because of the lacks of test, build, lint and description... I can do it if you tell me what is buggy on chrome 49.

@zh99998
Copy link
Contributor Author

zh99998 commented Sep 4, 2017

new URLSearchParams('?a=1').toString() #=> "%3Fa=1"

@lifaon74
Copy link
Owner

lifaon74 commented Sep 3, 2018

Fixed in 53ddfba ?

@lifaon74 lifaon74 closed this as completed Sep 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants