-
Notifications
You must be signed in to change notification settings - Fork 139
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
Investigate aligning application/x-www-form-urlencoded with URL's query #18
Comments
@annevk Both Firefox and Chrome escape \r and \n to "%0D%0A" when form submitting, should this spec align with them? test script:
|
@ziyunfei both https://url.spec.whatwg.org/#concept-urlencoded-byte-serializer and https://url.spec.whatwg.org/#query-state already escape those, no? |
Oh sorry, you mean that they turn a linebreak into CR LF. That is interesting and yes, maybe we should define that. Could you open a new issue for that? |
@ziyunfei I had another look and the linebreak behavior appears to be defined by step 4 (labeled "End") at https://html.spec.whatwg.org/multipage/forms.html#constructing-the-form-data-set. |
Query state encodes: 0x00-0x20, 0x22, 0x23, 0x3C, 0x3E, and 0x7E-Inf. urlencoded encodes: 0x00-0x19, 0x20 (as +, not %20), 0x21-0x29, 0x2B-0x2C, 0x2F, 0x40, 0x5B-0x5E, 0x60, 0x7B-Inf. Getting these aligned seems hard, though it would be good for |
[The steps](https://url.spec.whatwg.org/#concept-urlsearchparams-update) should run only when updated. See whatwg/url#350 and whatwg/url#18.
The fact that let a = 'http://localhost:9999/segment?foo=bar/baz? boo';
let b = 'http://localhost:9999/segment?foo=bar%2Fbaz%3F%20boo';
let urlA = new URL(a);
let urlB = new URL(b);
// Not equal:
console.log(urlA.search); // "?foo=bar/baz?%20boo"
console.log(urlB.search); // "?foo=bar%2Fbaz%3F%20boo"
// Equal:
console.log(urlA.searchParams.get("foo")); // "bar/baz? boo"
console.log(urlB.searchParams.get("foo")); // "bar/baz? boo"
// Equal, but both different from search:
console.log(urlA.searchParams.toString()); // "foo=bar%2Fbaz%3F+boo"
console.log(urlB.searchParams.toString()); // "foo=bar%2Fbaz%3F+boo" Perhaps, if we can't get full alignment, at least |
I think having |
I'd rather leave that to a separate class, e.g. FormData, or I guess since that name is taken, URLEncodedFormData. Maybe just use FormData but add FormData.fromURLEncoded() and formData.toURLEncoded() methods methods. |
It seems a little late given that |
I doubt people are using URLSearchParams with fetch that much on data that encodes differently and against servers that don't decode the differently-encoded data to the same result. After all, if you're making a compatibility argument, then we have no hope of fixing the OP, or changing URL encoding in general. |
Yeah, I haven't been hopeful about this issue because of that. Changing |
Note that they cannot ever be identical, as I think I reached the point where I think we should close this, but it's probably worth ensuring there's sufficient test coverage first and having another look at the results in browsers. |
That's not what we mean by identical. We mean that I'd strongly object to closing this; I'd like to make a concerted effort to fix this in browsers. If it's not fixable, then we need something new like |
There's already some differences with respect to escaping and #17 will enlarge that gap. Ideally they are the same I think.
The text was updated successfully, but these errors were encountered: