Skip to content

Commit f30abe2

Browse files
committed
update url_pattern to pass more wpt on node.js
1 parent aec5864 commit f30abe2

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

include/ada/implementation.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ bool can_parse(std::string_view input,
5353
* @param input valid UTF-8 string or URLPatternInit struct
5454
* @param base_url an optional valid UTF-8 string
5555
* @param options an optional url_pattern_options struct
56-
* @param provider an optional regex provider. if not provided, it will
57-
* use ada::url_pattern_regex::std_regex_provider
5856
* @return url_pattern instance
5957
*/
6058
template <url_pattern_regex::regex_concept regex_provider =

include/ada/url_pattern-inl.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@ url_pattern_component<regex_provider>::create_component_match_result(
4747
auto result =
4848
url_pattern_component_result{.input = std::string(input), .groups = {}};
4949

50-
// If input is empty, then groups will always be empty.
51-
if (input.empty()) {
52-
return result;
53-
}
54-
5550
// Optimization: Let's reserve the size.
5651
result.groups.reserve(exec_result.size());
5752

src/url_pattern_regex.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ std_regex_provider::regex_search(std::string_view input,
3131
return std::nullopt;
3232
}
3333
std::vector<std::optional<std::string>> matches;
34-
if (match_result.empty()) {
34+
// If input is empty, let's assume the result will be empty as well.
35+
if (input.empty() || match_result.empty()) {
3536
return matches;
3637
}
3738
matches.reserve(match_result.size());

tests/wpt_urlpattern_tests.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,32 @@ using namespace simdjson;
1414
constexpr std::string_view URL_PATTERN_TEST_DATA =
1515
"wpt/urlpatterntestdata.json";
1616

17+
TEST(wpt_urlpattern_tests, test_regex_difference) {
18+
// {
19+
// "pattern": [{ "pathname": "/foo/bar" }],
20+
// "inputs": [{ "pathname": "/foo/bar" }],
21+
// "expected_match": {
22+
// "pathname": { "input": "/foo/bar", "groups": {} }
23+
// }
24+
// }
25+
auto init = ada::url_pattern_init{};
26+
init.pathname = "/foo/bar";
27+
auto u =
28+
ada::parse_url_pattern<ada::url_pattern_regex::std_regex_provider>(init);
29+
ASSERT_TRUE(u);
30+
auto match = u->exec(init, nullptr);
31+
ASSERT_TRUE(match);
32+
ASSERT_TRUE(match->has_value());
33+
34+
std::unordered_map<std::string, std::optional<std::string>> empty_object{};
35+
36+
ASSERT_EQ(match->value().protocol.input, "");
37+
ASSERT_EQ(match->value().protocol.groups, empty_object);
38+
ASSERT_EQ(match->value().pathname.input, "/foo/bar");
39+
ASSERT_EQ(match->value().pathname.groups, empty_object);
40+
SUCCEED();
41+
}
42+
1743
TEST(wpt_urlpattern_tests, parser_tokenize_basic_tests) {
1844
auto tokenize_result =
1945
tokenize("*", ada::url_pattern_helpers::token_policy::STRICT);

0 commit comments

Comments
 (0)