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

Base URL and empty pathname in URLPatternInit #200

Open
sisidovski opened this issue Nov 21, 2023 · 0 comments
Open

Base URL and empty pathname in URLPatternInit #200

sisidovski opened this issue Nov 21, 2023 · 0 comments

Comments

@sisidovski
Copy link
Collaborator

sisidovski commented Nov 21, 2023

What is the issue with the URL Pattern Standard?

When we construct with URLPatternInit, containing an empty string pathname and the regular baseURL string, the result is a bit unintuitive. When the pathname is empty, it makes sense to me that the result is entirely inherited from the base URL, or keep it as the empty string. Also, it makes sense if the result is consistent with the case when URLPatternInit only has baseURL and doesn't have pathname field.

However, current behavior shows an inconsistent result like below.

// Empty pathname
new URLPattern({pathname: '', baseURL: 'https://example.com/a/b/c'}).pathname
=> '/a/b/'

// baseURL only
new URLPattern({baseURL: 'https://example.com/a/b/c'}).pathname
=> '/a/b/c'

Also, this behaves differently from the URL API.

new URL('', 'https://example.com/a/b/c').pathname
=> '/a/b/c'

This behavior was introduced in #107, and written in the step 17 in 3.2. URLPatternInit processing. I guess that was added to address the case when the pathname is a relative url such as *.jpg.

// Empty pathname
new URLPattern({pathname: '*.jpg', baseURL: 'https://example.com/a/b/c'}).pathname
=> '/a/b/*.jpg'

I wonder if we should process the step 17 if the pathname is empty, just inheriting the entire string from baseURL is intuitive, at least for me. Also, it would be nice to have the same behavior with the URL API not to surprise developers. WDYT?

cc: @jeremyroman @domenic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant