From 77d95d52351ebf51bc80ee21eea455de31a5e356 Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Tue, 15 Nov 2022 16:05:26 -0800 Subject: [PATCH] URLPattern: Escape pattern baseURL values. This addresses the problem described in this spec issue: https://github.com/WICG/urlpattern/issues/170 And this spec PR: https://github.com/WICG/urlpattern/pull/172 Bug: 1380534 Change-Id: I37b5f77e674f8c23ff59e6224d92c7a0d767e7cf Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4020802 Commit-Queue: Ben Kelly Reviewed-by: Jeremy Roman Cr-Commit-Position: refs/heads/main@{#1071919} --- urlpattern/resources/urlpatterntestdata.json | 45 ++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/urlpattern/resources/urlpatterntestdata.json b/urlpattern/resources/urlpatterntestdata.json index 58a1ea31b4bfb0..56b3a0c0f23dbc 100644 --- a/urlpattern/resources/urlpatterntestdata.json +++ b/urlpattern/resources/urlpatterntestdata.json @@ -2794,5 +2794,50 @@ "inputs": [{ "pathname": "/FOO", "search": "BAR", "hash": "BAZ", "baseURL": "https://example.com:8080" }], "expected_obj": "error" + }, + { + "pattern": [{ "search": "foo", "baseURL": "https://example.com/a/+/b" }], + "inputs": [{ "search": "foo", "baseURL": "https://example.com/a/+/b" }], + "exactly_empty_components": [ "username", "password", "port", "hash" ], + "expected_obj": { + "pathname": "/a/\\+/b" + }, + "expected_match": { + "hostname": { "input": "example.com", "groups": {} }, + "pathname": { "input": "/a/+/b", "groups": {} }, + "protocol": { "input": "https", "groups": {} }, + "search": { "input": "foo", "groups": {} } + } + }, + { + "pattern": [{ "hash": "foo", "baseURL": "https://example.com/?q=*&v=?&hmm={}&umm=()" }], + "inputs": [{ "hash": "foo", "baseURL": "https://example.com/?q=*&v=?&hmm={}&umm=()" }], + "exactly_empty_components": [ "username", "password", "port" ], + "expected_obj": { + "search": "q=\\*&v=\\?&hmm=\\{\\}&umm=\\(\\)" + }, + "expected_match": { + "hostname": { "input": "example.com", "groups": {} }, + "pathname": { "input": "/", "groups": {} }, + "protocol": { "input": "https", "groups": {} }, + "search": { "input": "q=*&v=?&hmm={}&umm=()", "groups": {} }, + "hash": { "input": "foo", "groups": {} } + } + }, + { + "pattern": [ "#foo", "https://example.com/?q=*&v=?&hmm={}&umm=()" ], + "inputs": [ "https://example.com/?q=*&v=?&hmm={}&umm=()#foo" ], + "exactly_empty_components": [ "username", "password", "port" ], + "expected_obj": { + "search": "q=\\*&v=\\?&hmm=\\{\\}&umm=\\(\\)", + "hash": "foo" + }, + "expected_match": { + "hostname": { "input": "example.com", "groups": {} }, + "pathname": { "input": "/", "groups": {} }, + "protocol": { "input": "https", "groups": {} }, + "search": { "input": "q=*&v=?&hmm={}&umm=()", "groups": {} }, + "hash": { "input": "foo", "groups": {} } + } } ]