Skip to content

Commit

Permalink
fix match
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Jan 4, 2025
1 parent 603a619 commit 1c431ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
10 changes: 8 additions & 2 deletions src/url_pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ result<std::optional<url_pattern_result>> url_pattern::match(
base_url_string);
// If baseURLString was given, throw a TypeError.
if (base_url_string) {
ada_log("failed to match because base_url_string was given");
return tl::unexpected(errors::type_error);
}

Expand All @@ -564,8 +565,10 @@ result<std::optional<url_pattern_result>> url_pattern::match(
std::get<url_pattern_init>(input), "url", protocol, username, password,
hostname, port, pathname, search, hash);

// If this throws an exception, catch it, and return null.
if (!apply_result.has_value()) {
return tl::unexpected(apply_result.error());
ada_log("match returned std::nullopt because process threw");
return std::nullopt;
}

// Set protocol to applyResult["protocol"].
Expand Down Expand Up @@ -604,7 +607,8 @@ result<std::optional<url_pattern_result>> url_pattern::match(
auto url_input = std::get<std::string_view>(input);
auto url = ada::parse<url_aggregator>(url_input);
if (!url) {
return tl::unexpected(errors::type_error);
ada_log("match throw because failed to parse url_input=", url_input);
return std::nullopt;
}

// Let baseURL be null.
Expand All @@ -619,6 +623,7 @@ result<std::optional<url_pattern_result>> url_pattern::match(

// If baseURL is failure, return null.
if (!base_url) {
ada_log("match returned std::nullopt because failed to parse base_url=", *base_url_string);
return std::nullopt;
}

Expand All @@ -635,6 +640,7 @@ result<std::optional<url_pattern_result>> url_pattern::match(

// If url is failure, return null.
if (!parsed_url) {
ada_log("match returned std::nullopt because url failed");
return std::nullopt;
}

Expand Down
12 changes: 6 additions & 6 deletions tests/wpt_urlpattern_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,13 @@ TEST(wpt_urlpattern_tests, urlpattern_test_data) {
base_url_view = std::string_view(base_url.value());
opt_base_url = &base_url_view;
}
if (std::holds_alternative<std::string>(init_variant)) {
auto str = std::get<std::string>(init_variant);
ada_log("init_variant is str=", str);
result = parse_result->exec(std::string_view(str), opt_base_url);
if (std::holds_alternative<std::string>(input_value)) {
auto str = std::get<std::string>(input_value);
ada_log("input_value is str=", str);
result = parse_result->exec(str, opt_base_url);
} else {
ada_log("init_variant is url_pattern_init");
auto obj = std::get<ada::url_pattern_init>(init_variant);
ada_log("input_value is url_pattern_init");
auto obj = std::get<ada::url_pattern_init>(input_value);
result = parse_result->exec(obj, opt_base_url);
}

Expand Down

0 comments on commit 1c431ba

Please sign in to comment.