Skip to content

Commit 9f8b316

Browse files
committed
update urlpatterntestdata.json
1 parent f2b423e commit 9f8b316

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

src/url_pattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ tl::expected<url_pattern_init, errors> url_pattern_init::process(
261261
// Set result["pathname"] to the result of process pathname for init given
262262
// result["pathname"], result["protocol"], and type.
263263
auto pathname_processing_result = process_pathname(
264-
*result.pathname, result.protocol.value_or("fake"), type);
264+
*result.pathname, result.protocol.value_or(""), type);
265265
if (!pathname_processing_result) {
266266
return tl::unexpected(pathname_processing_result.error());
267267
}

tests/wpt/urlpatterntestdata.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,15 @@
14031403
"pathname": { "input": "var%20x%20=%201;", "groups": {}}
14041404
}
14051405
},
1406+
{
1407+
"pattern": [{ "pathname": "/foo/bar" }],
1408+
"inputs": [ "./foo/bar", "https://example.com" ],
1409+
"expected_match": {
1410+
"hostname": { "input": "example.com", "groups": { "0": "example.com" } },
1411+
"pathname": { "input": "/foo/bar", "groups": {} },
1412+
"protocol": { "input": "https", "groups": { "0": "https" } }
1413+
}
1414+
},
14061415
{
14071416
"pattern": [{ "pathname": "/foo/bar" }],
14081417
"inputs": [ { "pathname": "/foo/bar" }, "https://example.com" ],
@@ -2624,6 +2633,13 @@
26242633
"pathname": { "input": "/FOO/BAR", "groups": {} }
26252634
}
26262635
},
2636+
{
2637+
"pattern": [{ "ignoreCase": true }],
2638+
"inputs": [{ "pathname": "/FOO/BAR" }],
2639+
"expected_match": {
2640+
"pathname": { "input": "/FOO/BAR", "groups": { "0": "/FOO/BAR" } }
2641+
}
2642+
},
26272643
{
26282644
"pattern": [ "https://example.com:8080/foo?bar#baz",
26292645
{ "ignoreCase": true }],
@@ -2720,4 +2736,4 @@
27202736
"hash": { "input": "foo", "groups": {} }
27212737
}
27222738
}
2723-
]
2739+
]

tests/wpt_urlpattern_tests.cpp

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,17 @@ TEST(wpt_urlpattern_tests, has_regexp_groups) {
105105
SUCCEED();
106106
}
107107

108-
ada::url_pattern_init parse_init(ondemand::object& object) {
108+
std::variant<ada::url_pattern_init, ada::url_pattern_options> parse_init(
109+
ondemand::object& object) {
109110
ada::url_pattern_init init{};
110111
for (auto field : object) {
111112
auto key = field.key().value();
112113
std::string_view value;
113-
EXPECT_FALSE(field.value().get_string(value));
114+
if (field.value().get_string(value)) {
115+
bool value_true;
116+
EXPECT_FALSE(field.value().get_bool().get(value_true));
117+
return ada::url_pattern_options{.ignore_case = value_true};
118+
}
114119
if (key == "protocol") {
115120
init.protocol = std::string(value);
116121
} else if (key == "username") {
@@ -177,8 +182,14 @@ parse_pattern_field(ondemand::array& patterns) {
177182
} else {
178183
EXPECT_TRUE(pattern.type() == ondemand::json_type::object);
179184
ondemand::object object = pattern.get_object();
180-
// TODO: URLPattern({ ignoreCase: true }) should also work...
181-
init_obj = parse_init(object);
185+
auto init_result = parse_init(object);
186+
if (std::holds_alternative<ada::url_pattern_init>(init_result)) {
187+
init_obj = std::get<ada::url_pattern_init>(init_result);
188+
} else {
189+
init_obj = {};
190+
options = std::get<ada::url_pattern_options>(init_result);
191+
return std::tuple(*init_obj, base_url, options);
192+
}
182193
}
183194
} else if (pattern_size == 1) {
184195
// The second value can be a base url or an option.
@@ -253,7 +264,8 @@ std::variant<std::string, ada::url_pattern_init> parse_inputs_array(
253264

254265
ondemand::object attribute;
255266
EXPECT_FALSE(input.get_object().get(attribute));
256-
return parse_init(attribute);
267+
// We always know that this function is called with url pattern init.
268+
return std::get<ada::url_pattern_init>(parse_init(attribute));
257269
}
258270

259271
return ada::url_pattern_init{};
@@ -368,15 +380,15 @@ TEST(wpt_urlpattern_tests, urlpattern_test_data) {
368380
}
369381
}
370382

371-
ondemand::array inputs;
372-
if (!main_object["inputs"].get_array().get(inputs)) {
373-
// Expected match can be:
374-
// - "error"
375-
// - null
376-
// - {} // response here.
377-
auto input_value = parse_inputs_array(inputs);
378-
// TODO: Parse "expected_match" field here.
379-
}
383+
// ondemand::array inputs;
384+
// if (!main_object["inputs"].get_array().get(inputs)) {
385+
// // Expected match can be:
386+
// // - "error"
387+
// // - null
388+
// // - {} // response here.
389+
// auto input_value = parse_inputs_array(inputs);
390+
// // TODO: Parse "expected_match" field here.
391+
// }
380392
}
381393
} catch (simdjson_error& error) {
382394
std::cerr << "JSON error: " << error.what() << " near "

0 commit comments

Comments
 (0)