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

How to get/set query string parameters? #37

Closed
glen-84 opened this issue Nov 5, 2015 · 27 comments
Closed

How to get/set query string parameters? #37

glen-84 opened this issue Nov 5, 2015 · 27 comments

Comments

@glen-84
Copy link

glen-84 commented Nov 5, 2015

Has URLUtils.searchParams been removed?

What is the best way to do this?

Unrelated: Why doesn't URL use the same terminology as RFC3986? (protocol -> scheme, hash -> fragment, search -> query, etc.)

@domenic
Copy link
Member

domenic commented Nov 7, 2015

It's simply not implemented yet in this library :). After we go through all the changes in #36, it will probably follow soon after.


The terminology is likely historical. Maybe @annevk knows why browsers originally chose those terms instead of the RFC ones. That RFC is certainly dated way after browsers implemented the location object, so maybe the real question is, why did RFC3986 not use the same terminology as browsers?

Regardless, that RFC is obsolete, and you should follow the URL Standard's terminology. (Although even that doesn't match the public API, again presumably for historical reasons.)

@glen-84
Copy link
Author

glen-84 commented Nov 7, 2015

Thanks @domenic.

@annevk
Copy link
Contributor

annevk commented Nov 7, 2015

I don't really know the history behind the terms, but it seemed wrong to deviate from the terms already established in JavaScript APIs in new APIs.

@glen-84
Copy link
Author

glen-84 commented Nov 7, 2015

Okay, makes sense.

@stevenvachon
Copy link
Contributor

How will PHP-like queries be handled?:

resource?array[0]=val1&array[1]=val2
resource?array[]=val1&array[]=val2

@Sebmaster
Copy link
Member

@stevenvachon See the API here. Your first example would be a bit weird since you'd have to do get('array[0]'), get('array[1]'), the latter would be much easier with getAll('array[]'). The brackets don't have any special meaning for the query parser.

@stevenvachon
Copy link
Contributor

Thanks!

@stevenvachon
Copy link
Contributor

Any progress on this?

@domenic
Copy link
Member

domenic commented Aug 22, 2016

As you can see from the lack of commits related to it, no.

@stevenvachon
Copy link
Contributor

Private progress does exist in general. Why is there no interest in implementing searchParams?

@glen-84
Copy link
Author

glen-84 commented Aug 22, 2016

@stevenvachon I'm using js-polyfills.

@stevenvachon
Copy link
Contributor

stevenvachon commented Nov 7, 2016

@glen-84 thank you, but unfortunately, I need an implementation of URL with URLSearchParams in Node. That library only works in a browser. I even tried hacking it:

const URL = eval("(function(self){"+ require("fs").readFileSync(__dirname+"/../node_modules/js-polyfills/url.js","utf8") +"; return self}({}))").URL;  // sigh

but it tries to use document

@mmcgahan
Copy link

mmcgahan commented Feb 1, 2017

@stevenvachon did you ever find a working polyfill? Node v7 now has native support for the URL api with require('url').URL (including support for url.searchParams), but I'm on a project that might be 'stuck' in Node 6 for a little while longer, so if there's something out there I can try, holler.

@stevenvachon
Copy link
Contributor

@mmcgahan nope 😞. I use Node v7's URL and this. As a result, I have to skip certain functionality when searchParams is missing.

@stevenvachon
Copy link
Contributor

We are really going to need URLSearchParams once Node v8.0 is released.

@domenic
Copy link
Member

domenic commented Mar 2, 2017

Adding +1s or their equivalent is not really helpful. A pull request would be appreciated instead.

@felixfbecker
Copy link

Can we just use https://www.npmjs.com/package/url-search-params as a dependency?

@stevenvachon
Copy link
Contributor

@felixfbecker it's not spec-compliant. They didn't know that a spec existed: WebReflection/url-search-params#19

@felixfbecker
Copy link

felixfbecker commented May 1, 2017

Well the implementation implements 99% of it, if sort() is missing then imo that's better than nothing.

I went ahead and did my best to file a "reasonable bug" so we can move on with this: WebReflection/url-search-params#22 😉

@domenic
Copy link
Member

domenic commented May 1, 2017

I don't intend to take on a dependency on a module maintained by someone with that attitude toward spec compliance.

It'll be better implemented in webidl2js anyway (e.g. USVString conversions).

@stevenvachon
Copy link
Contributor

@felixfbecker I don't think it's 99% compliant. It uses encodeURIComponent and decodeURIComponent, which is specifically not used in this library.

@felixfbecker
Copy link

Fair enough.

@stevenvachon
Copy link
Contributor

stevenvachon commented May 5, 2017

@TimothyGu do you still have an interest in doing this? You're the biggest expert on implementing it.

@felixfbecker
Copy link

url-search-params now supports .sort() as of WebReflection/url-search-params#23. Are there specific concerns/cases about encodeURIComponent that should be fixed that block an adoption here?

@domenic
Copy link
Member

domenic commented May 5, 2017

As stated above, we have no intention of using that library.

@TimothyGu
Copy link
Member

I'd still like to get support for sequence and unions (both used by URLSearchParams) from webidl2js first. In other words, it is blocked on jsdom/webidl2js#33 (pending review), and after that PR is merged, TimothyGu/webidl2js@1d42949.

@TimothyGu
Copy link
Member

PoC: #87

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

8 participants