Skip to content

Commit bce46f2

Browse files
nodejs-github-botaduh95
authored andcommitted
test: update WPT for urlpattern to 5847ee5cfa
PR-URL: #64436 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 71e6570 commit bce46f2

2 files changed

Lines changed: 72 additions & 1 deletion

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<title>URLPattern regexp groups work without a script context (detached frame)</title>
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
<body>
7+
<script>
8+
// These tests exercise URLPattern objects whose associated document/global
9+
// object has gone away (the owning frame is detached). This means URLPattern
10+
// is being used without a valid JavaScript context.
11+
function withDetachedPatternConstructor(t) {
12+
return new Promise(resolve => {
13+
const frame = document.createElement("iframe");
14+
frame.srcdoc = "";
15+
frame.onload = () => {
16+
const FrameURLPattern = frame.contentWindow.URLPattern;
17+
frame.remove();
18+
resolve(FrameURLPattern);
19+
};
20+
document.body.appendChild(frame);
21+
t.add_cleanup(() => frame.remove());
22+
});
23+
}
24+
25+
promise_test(async t => {
26+
const FrameURLPattern = await withDetachedPatternConstructor(t);
27+
const pattern = new FrameURLPattern({ pathname: "/books/:id(\\d+)" });
28+
29+
assert_true(pattern.hasRegExpGroups, "pattern should report regexp groups");
30+
31+
const result = pattern.exec("https://example.com/books/123");
32+
assert_not_equals(result, null, "regexp pattern should match");
33+
assert_equals(result.pathname.input, "/books/123");
34+
assert_equals(result.pathname.groups.id, "123");
35+
}, "Named regexp group matches after the owning frame is detached");
36+
37+
promise_test(async t => {
38+
const FrameURLPattern = await withDetachedPatternConstructor(t);
39+
const pattern = new FrameURLPattern({ pathname: "/books/:id(\\d+)" });
40+
41+
assert_equals(pattern.exec("https://example.com/books/abc"), null,
42+
"input that violates the regexp constraint should not match");
43+
}, "Non-matching regexp input returns null after the owning frame is detached");
44+
45+
promise_test(async t => {
46+
const FrameURLPattern = await withDetachedPatternConstructor(t);
47+
// Anonymous regexp group, exercised through test() rather than exec().
48+
const pattern = new FrameURLPattern({ pathname: "/(foo|bar)" });
49+
50+
assert_true(pattern.test("https://example.com/foo"),
51+
"anonymous regexp alternation should match after detach");
52+
assert_false(pattern.test("https://example.com/baz"),
53+
"anonymous regexp alternation should reject non-matching input after detach");
54+
}, "Anonymous regexp group via test() after the owning frame is detached");
55+
56+
promise_test(async t => {
57+
const FrameURLPattern = await withDetachedPatternConstructor(t);
58+
// Regexp groups across several components at once.
59+
const pattern = new FrameURLPattern({
60+
hostname: ":sub(.*)\\.example\\.com",
61+
pathname: "/v:version(\\d+)/:rest*",
62+
});
63+
64+
const result = pattern.exec("https://api.example.com/v2/users/42");
65+
assert_not_equals(result, null, "multi-component regexp pattern should match after detach");
66+
assert_equals(result.hostname.groups.sub, "api");
67+
assert_equals(result.pathname.groups.version, "2");
68+
assert_equals(result.pathname.groups.rest, "users/42");
69+
}, "Regexp groups across multiple components after the owning frame is detached");
70+
</script>
71+
</body>

test/fixtures/wpt/versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"path": "url"
7777
},
7878
"urlpattern": {
79-
"commit": "11a459a2b1d411506d9230edf9f2ef32babfeb0b",
79+
"commit": "5847ee5cfa4f710cbb78ab9ef5cc66f74433ee03",
8080
"path": "urlpattern"
8181
},
8282
"user-timing": {

0 commit comments

Comments
 (0)