-
Notifications
You must be signed in to change notification settings - Fork 23
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
Why does this test succeed with pathname "/foo/bar"? #240
Comments
Because new URL('./foo/bar', 'https://example.com').toString()
// 'https://example.com/foo/bar' Unless I'm misunderstanding your question? |
@jeremyroman You're right but canonicalize pathname function prepends /- to the input and disables URL path parsing for this particular edge case. Here's the ref for url pattern pathname canonicalize: https://urlpattern.spec.whatwg.org/#canonicalize-a-pathname Particularly this hack should be removed:
Using URL parser example, - character is not removed:
|
Right, and
The hack adds a |
I have some time to investigate this:
Inside the URLPattern parser, we call process a pattern init function. Ref https://urlpattern.spec.whatwg.org/#process-a-urlpatterninit For the given test, process a pattern init function section 17 (init pathname exists), subsection 1, sets the pathname as it is (as "./foo/bar"). Subsection 2 does not get executed because "https://example.com" does not have an opaque host. Hence, result pathname becomes init pathname. Later it calls process pathname for init function stated in subsection 3: "Set result["pathname"] to the result of process pathname for init given result["pathname"], result["protocol"], and type." This function is defined in https://urlpattern.spec.whatwg.org/#process-pathname-for-init Since type is "pattern", the pathname doesn't get changed. Later we see that, canonicalize a pathname method is called: https://urlpattern.spec.whatwg.org/#canonicalize-a-pathname This method prepends /- to the beginning because the first character is not a /. Referencing bullet point 3 inside canonicalize a pathname method. This results in URL parser to be called with /- prepended to the pathname, making the pathname . character not get removed
PS: @jeremyroman I reached out to you from Elements/Matrix. |
Ah, I see, and then you're saying that step 9 removes the first two characters, but leaves the |
So, in the Chromium implementation we have a |
I think the issue may be in step 17 of process a URLPatternInit, where the spec says "baseURL has an opaque path" but I suspect should read "baseURL does not have an opaque path". Chromium's implementation is I think that makes more sense than what it currently says (opaque paths are ones where it is less sensible to try and remove I'm still a little suspicious about how principled what we're doing there is, but perhaps this at least explains the discrepancy. |
Agree to Jeremy's latest comment. I think we can throw a TypeError if the baseURL has an opaque path in step 17 of process a URLPatternInit instead of saying "baseURL has an opaque path". This aligns with the current URL spec in https://url.spec.whatwg.org/#no-scheme-state
|
What is the issue with the URL Pattern Standard?
Referencing a WPT test:
canonicalize_pathname method adds
/-
and removes/-
from the method for several reasons. Ref: https://urlpattern.spec.whatwg.org/#canonicalize-a-pathnameWhy does the expected_obj has a pathname of
/foo/bar
but not./foo/bar
?cc @annevk @jeremyroman would you mind helping me understand the behavior here?
The text was updated successfully, but these errors were encountered: