diff --git a/include/ada/url_pattern-inl.h b/include/ada/url_pattern-inl.h index 02e7e085a..c5fa65400 100644 --- a/include/ada/url_pattern-inl.h +++ b/include/ada/url_pattern-inl.h @@ -52,7 +52,8 @@ url_pattern_component::create_component_match_result( // Let name be component’s group name list[index]. // Let value be Get(execResult, ToString(index)). // Set groups[name] to value. - if (auto str = exec_result[index].str(); !str.empty()) { + auto match = exec_result[index]; + if (auto str = match.str(); !str.empty()) { result.groups.insert({ group_name_list[index], str, diff --git a/include/ada/url_pattern.h b/include/ada/url_pattern.h index 8232221b2..fe2dae060 100644 --- a/include/ada/url_pattern.h +++ b/include/ada/url_pattern.h @@ -197,8 +197,11 @@ struct url_pattern_component_result { #if ADA_TESTING friend void PrintTo(const url_pattern_component_result& result, std::ostream* os) { - *os << "input: " << result.input - << ", groups_size: " << result.groups.size(); + *os << "input: '" << result.input + << "', group: "; + for (const auto& group : result.groups) { + *os << "(" << group.first << ", " << group.second << ") "; + } } #endif // ADA_TESTING }; diff --git a/tests/wpt/urlpatterntestdata.json b/tests/wpt/urlpatterntestdata.json index 9b2c49c2d..6fa7f907d 100644 --- a/tests/wpt/urlpatterntestdata.json +++ b/tests/wpt/urlpatterntestdata.json @@ -379,9 +379,8 @@ { "pattern": [{ "pathname": "/foo/:bar?" }], "inputs": [{ "pathname": "/foo" }], - "//": "The `null` below is translated to undefined in the test harness.", "expected_match": { - "pathname": { "input": "/foo", "groups": { "bar": null } } + "pathname": { "input": "/foo", "groups": {} } } }, { @@ -445,9 +444,8 @@ { "pattern": [{ "pathname": "/foo/:bar*" }], "inputs": [{ "pathname": "/foo" }], - "//": "The `null` below is translated to undefined in the test harness.", "expected_match": { - "pathname": { "input": "/foo", "groups": { "bar": null } } + "pathname": { "input": "/foo", "groups": {} } } }, { @@ -500,17 +498,15 @@ "expected_obj": { "pathname": "/foo/*?" }, - "//": "The `null` below is translated to undefined in the test harness.", "expected_match": { - "pathname": { "input": "/foo", "groups": { "0": null } } + "pathname": { "input": "/foo", "groups": {} } } }, { "pattern": [{ "pathname": "/foo/*?" }], "inputs": [{ "pathname": "/foo" }], - "//": "The `null` below is translated to undefined in the test harness.", "expected_match": { - "pathname": { "input": "/foo", "groups": { "0": null } } + "pathname": { "input": "/foo", "groups": {} } } }, { @@ -686,17 +682,15 @@ "expected_obj": { "pathname": "/foo/**" }, - "//": "The `null` below is translated to undefined in the test harness.", "expected_match": { - "pathname": { "input": "/foo", "groups": { "0": null } } + "pathname": { "input": "/foo", "groups": {} } } }, { "pattern": [{ "pathname": "/foo/**" }], "inputs": [{ "pathname": "/foo" }], - "//": "The `null` below is translated to undefined in the test harness.", "expected_match": { - "pathname": { "input": "/foo", "groups": { "0": null } } + "pathname": { "input": "/foo", "groups": {} } } }, { @@ -1823,10 +1817,9 @@ "hostname": "(sub.)?example.com", "pathname": "/foo" }, - "//": "The `null` below is translated to undefined in the test harness.", "expected_match": { "protocol": { "input": "https", "groups": {} }, - "hostname": { "input": "example.com", "groups": { "0": null } }, + "hostname": { "input": "example.com", "groups": {} }, "pathname": { "input": "/foo", "groups": {} } } }, @@ -1860,10 +1853,9 @@ "hostname": "(sub(?:.))?example.com", "pathname": "/foo" }, - "//": "The `null` below is translated to undefined in the test harness.", "expected_match": { "protocol": { "input": "https", "groups": {} }, - "hostname": { "input": "example.com", "groups": { "0": null } }, + "hostname": { "input": "example.com", "groups": {} }, "pathname": { "input": "/foo", "groups": {} } } }, @@ -2295,10 +2287,9 @@ "protocol": "data", "pathname": "text/javascript,let x = 100/:tens?5;" }, - "//": "The `null` below is translated to undefined in the test harness.", "expected_match": { "protocol": { "input": "data", "groups": {} }, - "pathname": { "input": "text/javascript,let x = 100/5;", "groups": { "tens": null } } + "pathname": { "input": "text/javascript,let x = 100/5;", "groups": {} } } }, { @@ -2608,9 +2599,8 @@ "expected_obj": { "pathname": "*(.*)?" }, - "//": "The `null` below is translated to undefined in the test harness.", "expected_match": { - "pathname": { "input": "foobar", "groups": { "0": "foobar", "1": null }} + "pathname": { "input": "foobar", "groups": { "0": "foobar" }} } }, { diff --git a/tests/wpt_urlpattern_tests.cpp b/tests/wpt_urlpattern_tests.cpp index 0a5a33d90..a9f122e0e 100644 --- a/tests/wpt_urlpattern_tests.cpp +++ b/tests/wpt_urlpattern_tests.cpp @@ -304,11 +304,10 @@ ada::url_pattern_component_result parse_component_result( ondemand::object groups; EXPECT_FALSE(element.value().get_object().get(groups)); for (auto group : groups) { - auto group_key = group.escaped_key().value(); + auto group_key = group.unescaped_key().value(); std::string_view group_value; EXPECT_FALSE(group.value().get_string(group_value)); - result.groups.insert_or_assign(std::string(group_key), - group_value); + result.groups.insert_or_assign(std::string(group_key), std::string(group_value)); } } }