Skip to content

Commit

Permalink
fix empty component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Dec 26, 2024
1 parent fbf9a4b commit 7393441
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,10 +976,13 @@ tl::expected<url_pattern, url_pattern_errors> parse_url_pattern_impl(
// is a string which represents its corresponding default port in radix-10
// using ASCII digits then set processedInit["port"] to the empty string.
// TODO: Optimization opportunity.
if (scheme::is_special(*processed_init->protocol) &&
std::to_string(scheme::get_special_port(*processed_init->protocol)) ==
processed_init->port) {
processed_init->port = "";
if (scheme::is_special(*processed_init->protocol)) {
std::string_view port = processed_init->port.value();
helpers::trim_c0_whitespace(port);
if (std::to_string(scheme::get_special_port(*processed_init->protocol)) ==
port) {
processed_init->port->clear();
}
}

// Let urlPattern be a new URL pattern.
Expand Down
29 changes: 29 additions & 0 deletions tests/wpt_urlpattern_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,35 @@ TEST(wpt_urlpattern_tests, urlpattern_test_data) {
<< main_object.raw_json().value() << std::endl;
}

ondemand::array exactly_empty_components;
if (!main_object["exactly_empty_components"].get_array().get(
exactly_empty_components)) {
for (auto component : exactly_empty_components) {
std::string_view key;
ASSERT_FALSE(component.get_string().get(key));
if (key == "hash") {
ASSERT_TRUE(parse_result->get_hash().empty());
} else if (key == "hostname") {
ASSERT_TRUE(parse_result->get_hostname().empty());
} else if (key == "pathname") {
ASSERT_TRUE(parse_result->get_pathname().empty());
} else if (key == "search") {
ASSERT_TRUE(parse_result->get_search().empty());
} else if (key == "port") {
ASSERT_TRUE(parse_result->get_port().empty());
} else if (key == "protocol") {
ASSERT_TRUE(parse_result->get_protocol().empty());
} else if (key == "username") {
ASSERT_TRUE(parse_result->get_username().empty());
} else if (key == "password") {
ASSERT_TRUE(parse_result->get_password().empty());
} else {
FAIL() << "Unknown key in exactly_empty_components: " << key
<< std::endl;
}
}
}

ondemand::object expected_obj;
if (!main_object["expected_obj"].get_object().get(expected_obj)) {
for (auto obj_element : expected_obj) {
Expand Down

0 comments on commit 7393441

Please sign in to comment.