| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 73bf0f0 commit 6da6ca7
2 files changed
| Original file line number | Diff line number | Diff 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> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -76,7 +76,7 @@ | |||
| 76 | 76 | "path": "url" | |
| 77 | 77 | }, | |
| 78 | 78 | "urlpattern": { | |
| 79 | - "commit": "11a459a2b1d411506d9230edf9f2ef32babfeb0b", | ||
| 79 | + "commit": "5847ee5cfa4f710cbb78ab9ef5cc66f74433ee03", | ||
| 80 | 80 | "path": "urlpattern" | |
| 81 | 81 | }, | |
| 82 | 82 | "user-timing": { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments