-
Notifications
You must be signed in to change notification settings - Fork 30
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
Decoding path parameters #93
Comments
It appears
|
It's one of the reserved characters and should be encoded before sending. |
URLPattern operates on URLs, not URIs. URLs only percent encode a few codepoints in the path: https://url.spec.whatwg.org/#path-percent-encode-set You can test this out on the live URL viewer here: https://jsdom.github.io/whatwg-url/#url=aHR0cDovL3QudC9bXQ==&base=YWJvdXQ6Ymxhbms= |
Is there a way how I can combine the real world that sends me encoded URI with URLPattern? |
Encoded and decoded URIs should be equal. (https://datatracker.ietf.org/doc/html/rfc2616#section-3.2.3) |
I need more context about the use case.
URL and URLPattern don't do any automatic decoding. Not sure if that is what you are asking or not. |
Yes, they don't decode URLs. They "canonicalize" URLs. new URL('%7E', 'http://h.d/').pathname === '/~' I understand that the problem is a little bit out of scope URLPattern implementation. In practice when we receive a request URI, we need to decode it before matching. It seems that there is no correct way to decode URI with encoded parameters to match the URI. If I receive an encoded URI, do you know what should I do with it before calling URLPattern.exec function? I mean if URLPattern doesn't do encoding/decoding, then I should do it by myself. I'm asking how I should do it. |
You're example is a bug in chrome and not interoperable across browsers. Per the URL spec the pathname should remain https://jsdom.github.io/whatwg-url/#url=JTdF&base=aHR0cDovL2guZC8= (Note, both firefox and safari correctly produce a pathname of Can you not call |
First of all, thanks very much for your help.
Example: |
And why when I put |
Using your example, this just seems to work for me: const pattern = new URLPattern({pathname: '/~:param'});
const encoded = '/%7E%2523';
const decoded = decodeURI(encoded);
const result = pattern.exec({pathname: decoded});
result.pathname.groups.param === '%23'; You can of course re-encode the end result if you want it in that form. I'm not sure I quite understand. |
Browser URL bars can do extra decoding that APIs like URL() and URLPattern() do not do. Also, chrome is not conformant at the API layer with other browsers. |
You skipped the decodeURIComponent step at the end.
|
And it seems like I can fetch an unsupported URL. await fetch('https://jsdom.github.io/whatwg-ur%6c/') |
@wanderview @kenchris @ivan-tymoshenko From the discussion above I can't decide if this is working according to specs, or if there is some bug that needs fixing. |
I think its working per spec and there is nothing actionable here. |
That was the point i was gravitating to also. |
Hi, I have a question about how should I work with encoded path parameters. There is one example that has all troublespots that I have.
I want to match the pattern url, and get param equal
%23
.The text was updated successfully, but these errors were encountered: