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

pathname . collapsing triggering too much #156

Closed
crowlKats opened this issue Jan 17, 2022 · 8 comments
Closed

pathname . collapsing triggering too much #156

crowlKats opened this issue Jan 17, 2022 · 8 comments

Comments

@crowlKats
Copy link

test code:

const p = new URLPattern({ pathname: '/:foo.' });
console.log(p.test({pathname: "/bar."}));
console.log(p.test({pathname: "/bar"}));

Chrome:

true
false

urlpattern-polyfill:

true
true

deno currently panics, but with a quick fix for the panic, i reach same result as urlpattern-polyfill. Is something missing in the spec?

@wanderview
Copy link
Member

wanderview commented Jan 18, 2022

Yes, this is a bug in the spec. The algorithm here:

https://wicg.github.io/urlpattern/#canonicalize-a-pathname

Creates a fakes URL and assigns the character to encode to the end of the pathname. A . after the implicit leading slash gets ellided by the URL normalization algorithm. We should special case this.

wanderview added a commit that referenced this issue Jan 18, 2022
This commit fixes an issue where '.' and '..' could be incorrectly
removed from a pathname during parsing.  This would happen in cases
where the encoding callback saw the '.' or '..' individually without
surrounding characters.  This would cause the algorithm to encode
them as '/.' or '/..' which the URL parser collapses to just '/'.

To avoid this behavior we explicitly check for '.' and '..' values
so they can be immediately returned without encoding.
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 18, 2022
This CL adds WPT test cases for the issue described in:

whatwg/urlpattern#156

Note, chromium does not suffer from the bug in the spec and already passes
the tests.

Change-Id: I121fe82bf1cdcb5b0ef6634d51d4f58beb57a2bc
wanderview added a commit that referenced this issue Jan 18, 2022
This commit fixes an issue where '.' and '..' could be incorrectly
removed from a pathname during parsing.  This would happen in cases
where the encoding callback saw the '.' or '..' individually without
surrounding characters.  This would cause the algorithm to encode
them as '/.' or '/..' which the URL parser collapses to just '/'.

To avoid this behavior we explicitly check for '.' and '..' values
so they can be immediately returned without encoding.
aarongable pushed a commit to chromium/chromium that referenced this issue Jan 18, 2022
This CL adds WPT test cases for the issue described in:

whatwg/urlpattern#156

Note, chromium does not suffer from the bug in the spec and already passes
the tests.

Change-Id: I121fe82bf1cdcb5b0ef6634d51d4f58beb57a2bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3399610
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Ben Kelly <wanderview@chromium.org>
Cr-Commit-Position: refs/heads/main@{#960622}
@wanderview
Copy link
Member

Hmm, I patched the immediate issue, but I'm not sure its adequate now.

Consider new URLPattern({ pathname: ':foo./' }). Per the spec and the polyfill this gets converted to just :foo which seems wrong. Chromium preserves it as :foo./ instead.

On the flip side, though, what would we expect for new URLPattern({ pathname: './foo' }). Note there is no base URL here. Chromium keeps it as ./foo, but the spec and polyfill collapse the ./ to just foo. I think the chromium behavior is more correct here, but not as sure. (Note, if there is a base URL with a pathname ending in a slash, then chromium does collapse correctly.)

I need to think about what the correct fix is here.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 18, 2022
This CL adds WPT test cases for the issue described in:

whatwg/urlpattern#156

Note, chromium does not suffer from the bug in the spec and already passes
the tests.

Change-Id: I121fe82bf1cdcb5b0ef6634d51d4f58beb57a2bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3399610
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Ben Kelly <wanderview@chromium.org>
Cr-Commit-Position: refs/heads/main@{#960622}
@wanderview
Copy link
Member

I think maybe the solution could be pre-pending a prefix like "/-" before we pass a value to the URL pathname parser if the value does not already start with a slash. Then we would strip it back off at the end.

@domenic
Copy link
Member

domenic commented Jan 18, 2022

I think this could benefit from some discussion with users, if possible. It kind of depends how much people expect these sort of strings to be "path-like" (where ./foo is equivalent to foo) or "regexp-like", and how inserting :bar in various locations changes their intuition. I don't have much of a handle on that...

@wanderview
Copy link
Member

I'm not sure users will have a strong informed opinion here. Its a bit esoteric.

Also, there is a rationale for the chromium behavior. We only perform . and .. collapsing when we are certain there are slashes on both sides.

The issue with the non-chromium behavior is an artifact of how we have to use the URL parser algorithm that implicitly inserts a leading / because its resolving full URLs. We basically don't want that behavior here.

I also think keeping new URLPattern({ pathname: "./foo" }) as ./foo is principled because it has not been resolved against a base URL. Its an unresolved path and so the leading ./ does not meet the criteria for collapsing.

Having thought this through more I feel pretty strongly that we should stick with the chromium behavior.

@wanderview
Copy link
Member

FWIW, prepending /- and then later removing it fixes all the issues in the polyfill.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 18, 2022
This CL adds WPT test cases for the issue described in:

whatwg/urlpattern#156

Note, chromium does not suffer from the bug in the spec and already passes
the tests.

Change-Id: I121fe82bf1cdcb5b0ef6634d51d4f58beb57a2bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3399610
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Ben Kelly <wanderview@chromium.org>
Cr-Commit-Position: refs/heads/main@{#960622}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 18, 2022
This CL adds some more test cases for issues discussed in:

whatwg/urlpattern#156

Change-Id: I885a61aa6be3d416babfa7c23b19465d0c63d07a
@wanderview wanderview changed the title pathname /:foo. not acting correctly pathname . collapsing triggering too much Jan 19, 2022
@wanderview
Copy link
Member

Another issue I thought of is new URLPattern({ pathname: '/.*' }) like you are trying to match dot files. Unfortunately the URL parser ends up seeing /. in this situation and collapses the whole thing to /*. This one affects chromium, the spec, and the polyfill.

This one would be a bit more complex to fix. We would have to do something like check for additional content after a trailing /. and then bypass the encoder for the /. in that case.

We could also just leave this as a quirk of the API, but I worry that the "match dotfiles" case might actually be something people will hit. There is a work around with /(\\.)* I guess.

aarongable pushed a commit to chromium/chromium that referenced this issue Jan 19, 2022
This CL adds some more test cases for issues discussed in:

whatwg/urlpattern#156

Change-Id: I885a61aa6be3d416babfa7c23b19465d0c63d07a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3399895
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Ben Kelly <wanderview@chromium.org>
Cr-Commit-Position: refs/heads/main@{#960951}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 19, 2022
This CL adds some more test cases for issues discussed in:

whatwg/urlpattern#156

Change-Id: I885a61aa6be3d416babfa7c23b19465d0c63d07a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3399895
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Ben Kelly <wanderview@chromium.org>
Cr-Commit-Position: refs/heads/main@{#960951}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 19, 2022
This CL adds some more test cases for issues discussed in:

whatwg/urlpattern#156

Change-Id: I885a61aa6be3d416babfa7c23b19465d0c63d07a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3399895
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Ben Kelly <wanderview@chromium.org>
Cr-Commit-Position: refs/heads/main@{#960951}
@wanderview
Copy link
Member

I decided to move #156 (comment) off into its own issue at #159.

wanderview added a commit that referenced this issue Jan 19, 2022
This commit does a better job of protecting `.` and `..` sequences in
the encoding callback by disabling the automatic insertion of a
leading slash.  Without this change we `:foo./` would get converted
to just `:foo` which is incorrect.
wanderview added a commit that referenced this issue Jan 19, 2022
This commit does a better job of protecting `.` and `..` sequences in
the encoding callback by disabling the automatic insertion of a
leading slash.  Without this change we `:foo./` would get converted
to just `:foo` which is incorrect.
wanderview added a commit that referenced this issue Jan 19, 2022
This commit does a better job of protecting `.` and `..` sequences in
the encoding callback by disabling the automatic insertion of a
leading slash.  Without this change we `:foo./` would get converted
to just `:foo` which is incorrect.
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Feb 5, 2022
….' and '..' in pathname., a=testonly

Automatic update from web-platform-tests
URLPattern: Add WPT cases for isolated '.' and '..' in pathname.

This CL adds WPT test cases for the issue described in:

whatwg/urlpattern#156

Note, chromium does not suffer from the bug in the spec and already passes
the tests.

Change-Id: I121fe82bf1cdcb5b0ef6634d51d4f58beb57a2bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3399610
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Ben Kelly <wanderview@chromium.org>
Cr-Commit-Position: refs/heads/main@{#960622}

--

wpt-commits: fd132aec57c531fdbb71cc7cd18aed97a8e3492a
wpt-pr: 32440
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Feb 5, 2022
…'..'., a=testonly

Automatic update from web-platform-tests
URLPattern: More WPT tests with '.' and '..'.

This CL adds some more test cases for issues discussed in:

whatwg/urlpattern#156

Change-Id: I885a61aa6be3d416babfa7c23b19465d0c63d07a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3399895
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Ben Kelly <wanderview@chromium.org>
Cr-Commit-Position: refs/heads/main@{#960951}

--

wpt-commits: b717651264109d1ac96e922431b7b846ba8d599f
wpt-pr: 32442
jamienicol pushed a commit to jamienicol/gecko that referenced this issue Feb 7, 2022
….' and '..' in pathname., a=testonly

Automatic update from web-platform-tests
URLPattern: Add WPT cases for isolated '.' and '..' in pathname.

This CL adds WPT test cases for the issue described in:

whatwg/urlpattern#156

Note, chromium does not suffer from the bug in the spec and already passes
the tests.

Change-Id: I121fe82bf1cdcb5b0ef6634d51d4f58beb57a2bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3399610
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Ben Kelly <wanderview@chromium.org>
Cr-Commit-Position: refs/heads/main@{#960622}

--

wpt-commits: fd132aec57c531fdbb71cc7cd18aed97a8e3492a
wpt-pr: 32440
jamienicol pushed a commit to jamienicol/gecko that referenced this issue Feb 7, 2022
…'..'., a=testonly

Automatic update from web-platform-tests
URLPattern: More WPT tests with '.' and '..'.

This CL adds some more test cases for issues discussed in:

whatwg/urlpattern#156

Change-Id: I885a61aa6be3d416babfa7c23b19465d0c63d07a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3399895
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Ben Kelly <wanderview@chromium.org>
Cr-Commit-Position: refs/heads/main@{#960951}

--

wpt-commits: b717651264109d1ac96e922431b7b846ba8d599f
wpt-pr: 32442
mjfroman pushed a commit to mjfroman/moz-libwebrtc-third-party that referenced this issue Oct 14, 2022
This CL adds WPT test cases for the issue described in:

whatwg/urlpattern#156

Note, chromium does not suffer from the bug in the spec and already passes
the tests.

Change-Id: I121fe82bf1cdcb5b0ef6634d51d4f58beb57a2bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3399610
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Ben Kelly <wanderview@chromium.org>
Cr-Commit-Position: refs/heads/main@{#960622}
NOKEYCHECK=True
GitOrigin-RevId: 568c89e80683904edfdd6f313983768407509b5e
mjfroman pushed a commit to mjfroman/moz-libwebrtc-third-party that referenced this issue Oct 14, 2022
This CL adds some more test cases for issues discussed in:

whatwg/urlpattern#156

Change-Id: I885a61aa6be3d416babfa7c23b19465d0c63d07a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3399895
Reviewed-by: Domenic Denicola <domenic@chromium.org>
Commit-Queue: Ben Kelly <wanderview@chromium.org>
Cr-Commit-Position: refs/heads/main@{#960951}
NOKEYCHECK=True
GitOrigin-RevId: 9b537a98e0581fde0e94987363584c06afdb3184
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

3 participants