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

Removing trailing C0 control or space at basic URL parser makes difference with override #542

Closed
watilde opened this issue Sep 8, 2020 · 7 comments
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: api

Comments

@watilde
Copy link

watilde commented Sep 8, 2020

Steps to reproduce

The below console.log should show the same result. Otherwise: #542 (comment)

const hash = 'test\x00';
const url = new URL(`http://a.com/#${hash}`)

console.log(url.href)
// => http://a.com/#test

url.hash = hash
console.log(url.href)
// => http://a.com/#test%00

Summary

Because the basic URL parser removes trailing c0 control or space only when url is not given, it makes a difference with override.

Refs: https://url.spec.whatwg.org/#url-parsing

1. If url is not given:
  1.Set url to a new URL.
  2. If input contains any leading or trailing C0 control or space, validation error.
  3. Remove any leading and **trailing C0 control or space** from input.

Potential solutions would be below two:

  1. Opt-in constructor argument, such as new URL(..., { noTrim: true }). Refs: Removing trailing C0 control or space at basic URL parser makes difference with override #542 (comment)
  2. Allows basic URL parser to use c0 control or space
  3. Remove c0 control or space always
@annevk
Copy link
Member

annevk commented Sep 8, 2020

Why should it show the same result? They're not the same API.

@watilde
Copy link
Author

watilde commented Sep 8, 2020

It always requires the override state when users want to put \x00 at the end of the URL so that I was wondering if the basic parser should provide a way to reproduce the same result with the override state's result when an input has the same value which is \x00 at the end in this case.

@annevk
Copy link
Member

annevk commented Sep 8, 2020

That might be reasonable, but should be an opt-in constructor argument of sorts I think. E.g., new URL(..., { noTrim: true }).

@watilde
Copy link
Author

watilde commented Sep 8, 2020

Right. The optional constructor argument design would be better for backward compatibility. I just updated the description of this PR to address the discussion.

@annevk annevk added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: api labels Sep 8, 2020
@domenic
Copy link
Member

domenic commented Sep 8, 2020

FWIW I would prefer to always remove, in both APIs. It would be nice if the URL data model could guarantee no trailing C0 control or space instead of having the trimming being a parsing quirk.

@annevk
Copy link
Member

annevk commented Sep 9, 2020

The data model already guarantees it, no? It ends up ending with %00, not U+0000. Which is also why it seems reasonable to allow the parser to do that transformation for you if you want it.

I doubt we can change the API generally and given that the API is for individual components it's already a very different proposition. Why should port trim them, for instance?

@annevk
Copy link
Member

annevk commented Jan 17, 2023

Compared to other API requests we got this hasn't gotten a lot of interest so I'm inclined to close this until we see more of a demand in libraries.

@annevk annevk closed this as completed Feb 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: api
Development

No branches or pull requests

3 participants