Skip to content

Updates for ada 3.1.1 / version 1.18.0 #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 35 additions & 36 deletions ada_url/ada.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* auto-generated on 2025-02-11 09:47:50 -0500. Do not edit! */
/* auto-generated on 2025-02-23 20:08:55 -0500. Do not edit! */
/* begin file src/ada.cpp */
#include "ada.h"
/* begin file src/checkers.cpp */
Expand Down Expand Up @@ -15225,7 +15225,7 @@ inline void url_aggregator::consume_prepared_path(std::string_view input) {
namespace ada {

tl::expected<url_pattern_init, errors> url_pattern_init::process(
url_pattern_init init, std::string_view type,
url_pattern_init init, url_pattern_init::process_type type,
std::optional<std::string_view> protocol,
std::optional<std::string_view> username,
std::optional<std::string_view> password,
Expand Down Expand Up @@ -15287,8 +15287,8 @@ tl::expected<url_pattern_init, errors> url_pattern_init::process(
// If type is not "pattern" and init contains none of "protocol",
// "hostname", "port" and "username", then set result["username"] to the
// result of processing a base URL string given baseURL’s username and type.
if (type != "pattern" && !init.protocol && !init.hostname && !init.port &&
!init.username) {
if (type != process_type::pattern && !init.protocol && !init.hostname &&
!init.port && !init.username) {
result.username = url_pattern_helpers::process_base_url_string(
base_url->get_username(), type);
}
Expand All @@ -15298,8 +15298,8 @@ tl::expected<url_pattern_init, errors> url_pattern_init::process(
// "hostname", "port", "username" and "password", then set
// result["password"] to the result of processing a base URL string given
// baseURL’s password and type.
if (type != "pattern" && !init.protocol && !init.hostname && !init.port &&
!init.username && !init.password) {
if (type != process_type::pattern && !init.protocol && !init.hostname &&
!init.port && !init.username && !init.password) {
result.password = url_pattern_helpers::process_base_url_string(
base_url->get_password(), type);
}
Expand Down Expand Up @@ -15418,6 +15418,8 @@ tl::expected<url_pattern_init, errors> url_pattern_init::process(
!url_pattern_helpers::is_absolute_pathname(*result.pathname, type)) {
// Let baseURLPath be the result of running process a base URL string
// given the result of URL path serializing baseURL and type.
// TODO: Optimization opportunity: Avoid returning a string if no slash
// exist.
std::string base_url_path = url_pattern_helpers::process_base_url_string(
base_url->get_pathname(), type);

Expand All @@ -15430,12 +15432,12 @@ tl::expected<url_pattern_init, errors> url_pattern_init::process(
if (slash_index != std::string::npos) {
// Let new pathname be the code point substring from 0 to slash index +
// 1 within baseURLPath.
std::string new_pathname = base_url_path.substr(0, slash_index + 1);
base_url_path.resize(slash_index + 1);
// Append result["pathname"] to the end of new pathname.
ADA_ASSERT_TRUE(result.pathname.has_value());
new_pathname.append(result.pathname.value());
base_url_path.append(std::move(*result.pathname));
// Set result["pathname"] to new pathname.
result.pathname = std::move(new_pathname);
result.pathname = std::move(base_url_path);
}
}

Expand Down Expand Up @@ -15473,56 +15475,56 @@ tl::expected<url_pattern_init, errors> url_pattern_init::process(
}

tl::expected<std::string, errors> url_pattern_init::process_protocol(
std::string_view value, std::string_view type) {
std::string_view value, process_type type) {
ada_log("process_protocol=", value, " [", type, "]");
// Let strippedValue be the given value with a single trailing U+003A (:)
// removed, if any.
if (value.ends_with(":")) {
value.remove_suffix(1);
}
// If type is "pattern" then return strippedValue.
if (type == "pattern") {
if (type == process_type::pattern) {
return std::string(value);
}
// Return the result of running canonicalize a protocol given strippedValue.
return url_pattern_helpers::canonicalize_protocol(value);
}

tl::expected<std::string, errors> url_pattern_init::process_username(
std::string_view value, std::string_view type) {
std::string_view value, process_type type) {
// If type is "pattern" then return value.
if (type == "pattern") {
if (type == process_type::pattern) {
return std::string(value);
}
// Return the result of running canonicalize a username given value.
return url_pattern_helpers::canonicalize_username(value);
}

tl::expected<std::string, errors> url_pattern_init::process_password(
std::string_view value, std::string_view type) {
std::string_view value, process_type type) {
// If type is "pattern" then return value.
if (type == "pattern") {
if (type == process_type::pattern) {
return std::string(value);
}
// Return the result of running canonicalize a password given value.
return url_pattern_helpers::canonicalize_password(value);
}

tl::expected<std::string, errors> url_pattern_init::process_hostname(
std::string_view value, std::string_view type) {
std::string_view value, process_type type) {
ada_log("process_hostname value=", value, " type=", type);
// If type is "pattern" then return value.
if (type == "pattern") {
if (type == process_type::pattern) {
return std::string(value);
}
// Return the result of running canonicalize a hostname given value.
return url_pattern_helpers::canonicalize_hostname(value);
}

tl::expected<std::string, errors> url_pattern_init::process_port(
std::string_view port, std::string_view protocol, std::string_view type) {
std::string_view port, std::string_view protocol, process_type type) {
// If type is "pattern" then return portValue.
if (type == "pattern") {
if (type == process_type::pattern) {
return std::string(port);
}
// Return the result of running canonicalize a port given portValue and
Expand All @@ -15531,9 +15533,9 @@ tl::expected<std::string, errors> url_pattern_init::process_port(
}

tl::expected<std::string, errors> url_pattern_init::process_pathname(
std::string_view value, std::string_view protocol, std::string_view type) {
std::string_view value, std::string_view protocol, process_type type) {
// If type is "pattern" then return pathnameValue.
if (type == "pattern") {
if (type == process_type::pattern) {
return std::string(value);
}

Expand All @@ -15549,31 +15551,31 @@ tl::expected<std::string, errors> url_pattern_init::process_pathname(
}

tl::expected<std::string, errors> url_pattern_init::process_search(
std::string_view value, std::string_view type) {
std::string_view value, process_type type) {
// Let strippedValue be the given value with a single leading U+003F (?)
// removed, if any.
if (value.starts_with("?")) {
value.remove_prefix(1);
}
ADA_ASSERT_TRUE(!value.starts_with("?"));
// If type is "pattern" then return strippedValue.
if (type == "pattern") {
if (type == process_type::pattern) {
return std::string(value);
}
// Return the result of running canonicalize a search given strippedValue.
return url_pattern_helpers::canonicalize_search(value);
}

tl::expected<std::string, errors> url_pattern_init::process_hash(
std::string_view value, std::string_view type) {
std::string_view value, process_type type) {
// Let strippedValue be the given value with a single leading U+0023 (#)
// removed, if any.
if (value.starts_with("#")) {
value.remove_prefix(1);
}
ADA_ASSERT_TRUE(!value.starts_with("#"));
// If type is "pattern" then return strippedValue.
if (type == "pattern") {
if (type == process_type::pattern) {
return std::string(value);
}
// Return the result of running canonicalize a hash given strippedValue.
Expand All @@ -15599,7 +15601,6 @@ generate_regular_expression_and_name_list(

// Let name list be a new list
std::vector<std::string> name_list{};
const std::string full_wildcard_regexp_value = ".*";

// For each part of part list:
for (const url_pattern_part& part : part_list) {
Expand Down Expand Up @@ -15645,7 +15646,7 @@ generate_regular_expression_and_name_list(
// Otherwise if part's type is "full-wildcard"
else if (part.type == url_pattern_part_type::FULL_WILDCARD) {
// then set regexp value to full wildcard regexp value.
regexp_value = full_wildcard_regexp_value;
regexp_value = ".*";
}

// If part's prefix is the empty string and part's suffix is the empty
Expand Down Expand Up @@ -15724,7 +15725,7 @@ generate_regular_expression_and_name_list(
result += "$";

// Return (result, name list)
return {result, name_list};
return {std::move(result), std::move(name_list)};
}

bool is_ipv6_address(std::string_view input) noexcept {
Expand Down Expand Up @@ -16387,33 +16388,31 @@ std::string escape_regexp_string(std::string_view input) {
}

std::string process_base_url_string(std::string_view input,
std::string_view type) {
url_pattern_init::process_type type) {
// If type is not "pattern" return input.
if (type != "pattern") {
if (type != url_pattern_init::process_type::pattern) {
return std::string(input);
}
// Return the result of escaping a pattern string given input.
return escape_pattern_string(input);
}

constexpr bool is_absolute_pathname(std::string_view input,
std::string_view type) noexcept {
constexpr bool is_absolute_pathname(
std::string_view input, url_pattern_init::process_type type) noexcept {
// If input is the empty string, then return false.
if (input.empty()) [[unlikely]] {
return false;
}
// If input[0] is U+002F (/), then return true.
if (input.starts_with("/")) return true;
// If type is "url", then return false.
if (type == "url") return false;
if (type == url_pattern_init::process_type::url) return false;
// If input’s code point length is less than 2, then return false.
if (input.size() < 2) return false;
// If input[0] is U+005C (\) and input[1] is U+002F (/), then return true.
if (input.starts_with("\\/")) return true;
// If input[0] is U+007B ({) and input[1] is U+002F (/), then return true.
if (input.starts_with("{/")) return true;
// Return false.
return false;
return input[1] == '/' && (input[0] == '\\' || input[0] == '{');
}

std::string generate_pattern_string(
Expand Down
Loading
Loading