Skip to content

Commit

Permalink
URLPattern: Fix matched values for ':name*' patterns.
Browse files Browse the repository at this point in the history
This fixes the problem where:

  const p = new URLPattern({ pathname: ':name*' });
  const r = p.exec('foobar');
  console.log(r.pathname.groups.name);

Would log 'r' instead of 'foobar'.

This is an upstream bug in path-to-regexp as well:

pillarjs/path-to-regexp#260

Fixed: 1243773
Change-Id: I402d2b8cba48386d9ae02a493068488a7ad91d70
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3123654
Commit-Queue: Ben Kelly <wanderview@chromium.org>
Reviewed-by: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/main@{#917069}
  • Loading branch information
wanderview authored and chromium-wpt-export-bot committed Sep 1, 2021
1 parent 1aa215c commit 72cebca
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions urlpattern/resources/urlpatterntestdata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2189,5 +2189,47 @@
{
"pattern": [{ "pathname": "/foo" }, "https://example.com" ],
"expected_obj": "error"
},
{
"pattern": [{ "pathname": ":name*" }],
"inputs": [{ "pathname": "foobar" }],
"expected_match": {
"pathname": { "input": "foobar", "groups": { "name": "foobar" }}
}
},
{
"pattern": [{ "pathname": ":name+" }],
"inputs": [{ "pathname": "foobar" }],
"expected_match": {
"pathname": { "input": "foobar", "groups": { "name": "foobar" }}
}
},
{
"pattern": [{ "pathname": ":name" }],
"inputs": [{ "pathname": "foobar" }],
"expected_match": {
"pathname": { "input": "foobar", "groups": { "name": "foobar" }}
}
},
{
"pattern": [{ "protocol": ":name*" }],
"inputs": [{ "protocol": "foobar" }],
"expected_match": {
"protocol": { "input": "foobar", "groups": { "name": "foobar" }}
}
},
{
"pattern": [{ "protocol": ":name+" }],
"inputs": [{ "protocol": "foobar" }],
"expected_match": {
"protocol": { "input": "foobar", "groups": { "name": "foobar" }}
}
},
{
"pattern": [{ "protocol": ":name" }],
"inputs": [{ "protocol": "foobar" }],
"expected_match": {
"protocol": { "input": "foobar", "groups": { "name": "foobar" }}
}
}
]

0 comments on commit 72cebca

Please sign in to comment.