diff --git a/deps/ada/ada.cpp b/deps/ada/ada.cpp index 28ca61f8b801ab..72512a0651826e 100644 --- a/deps/ada/ada.cpp +++ b/deps/ada/ada.cpp @@ -1,7 +1,8 @@ -/* auto-generated on 2024-05-30 22:24:57 -0400. Do not edit! */ +/* auto-generated on 2024-07-06 17:38:56 -0400. Do not edit! */ /* begin file src/ada.cpp */ #include "ada.h" /* begin file src/checkers.cpp */ + #include namespace ada::checkers { @@ -9794,6 +9795,10 @@ ADA_POP_DISABLE_WARNINGS namespace ada::unicode { +constexpr bool is_tabs_or_newline(char c) noexcept { + return c == '\r' || c == '\n' || c == '\t'; +} + constexpr uint64_t broadcast(uint8_t v) noexcept { return 0x101010101010101ull * v; } @@ -9828,13 +9833,8 @@ ada_really_inline bool has_tabs_or_newline( std::string_view user_input) noexcept { // first check for short strings in which case we do it naively. if (user_input.size() < 16) { // slow path - for (size_t i = 0; i < user_input.size(); i++) { - if (user_input[i] == '\r' || user_input[i] == '\n' || - user_input[i] == '\t') { - return true; - } - } - return false; + return std::any_of(user_input.begin(), user_input.end(), + is_tabs_or_newline); } // fast path for long strings (expected to be common) size_t i = 0; @@ -9872,13 +9872,8 @@ ada_really_inline bool has_tabs_or_newline( std::string_view user_input) noexcept { // first check for short strings in which case we do it naively. if (user_input.size() < 16) { // slow path - for (size_t i = 0; i < user_input.size(); i++) { - if (user_input[i] == '\r' || user_input[i] == '\n' || - user_input[i] == '\t') { - return true; - } - } - return false; + return std::any_of(user_input.begin(), user_input.end(), + is_tabs_or_newline); } // fast path for long strings (expected to be common) size_t i = 0; @@ -10263,10 +10258,6 @@ std::string percent_encode(const std::string_view input, return out; } -std::string to_unicode(std::string_view input) { - return ada::idna::to_unicode(input); -} - } // namespace ada::unicode /* end file src/unicode.cpp */ /* begin file src/serializers.cpp */ @@ -10359,7 +10350,8 @@ namespace ada { template ada_warn_unused tl::expected parse( std::string_view input, const result_type* base_url) { - result_type u = ada::parser::parse_url(input, base_url); + result_type u = + ada::parser::parse_url_impl(input, base_url); if (!u.is_valid) { return tl::unexpected(errors::generic_error); } @@ -10395,16 +10387,22 @@ std::string href_from_file(std::string_view input) { } bool can_parse(std::string_view input, const std::string_view* base_input) { - ada::result base; + ada::url_aggregator base_aggregator; ada::url_aggregator* base_pointer = nullptr; + if (base_input != nullptr) { - base = ada::parse(*base_input); - if (!base) { + base_aggregator = ada::parser::parse_url_impl( + *base_input, nullptr); + if (!base_aggregator.is_valid) { return false; } - base_pointer = &base.value(); + base_pointer = &base_aggregator; } - return ada::parse(input, base_pointer).has_value(); + + ada::url_aggregator result = + ada::parser::parse_url_impl(input, + base_pointer); + return result.is_valid; } ada_warn_unused std::string to_string(ada::encoding_type type) { @@ -12139,11 +12137,12 @@ bool url::set_href(const std::string_view input) { #include + namespace ada::parser { -template -result_type parse_url(std::string_view user_input, - const result_type* base_url) { +template +result_type parse_url_impl(std::string_view user_input, + const result_type* base_url) { // We can specialize the implementation per type. // Important: result_type_is_ada_url is evaluated at *compile time*. This // means that doing if constexpr(result_type_is_ada_url) { something } else { @@ -12178,7 +12177,7 @@ result_type parse_url(std::string_view user_input, if (!url.is_valid) { return url; } - if constexpr (result_type_is_ada_url_aggregator) { + if constexpr (result_type_is_ada_url_aggregator && store_values) { // Most of the time, we just need user_input.size(). // In some instances, we may need a bit more. /////////////////////////// @@ -12195,9 +12194,6 @@ result_type parse_url(std::string_view user_input, helpers::leading_zeroes(uint32_t(1 | user_input.size()))) + 1; url.reserve(reserve_capacity); - // - // - // } std::string tmp_buffer; std::string_view internal_input; @@ -12420,32 +12416,36 @@ result_type parse_url(std::string_view user_input, password_token_seen = password_token_location != std::string_view::npos; - if (!password_token_seen) { - if constexpr (result_type_is_ada_url) { - url.username += unicode::percent_encode( - authority_view, character_sets::USERINFO_PERCENT_ENCODE); - } else { - url.append_base_username(unicode::percent_encode( - authority_view, character_sets::USERINFO_PERCENT_ENCODE)); - } - } else { - if constexpr (result_type_is_ada_url) { - url.username += unicode::percent_encode( - authority_view.substr(0, password_token_location), - character_sets::USERINFO_PERCENT_ENCODE); - url.password += unicode::percent_encode( - authority_view.substr(password_token_location + 1), - character_sets::USERINFO_PERCENT_ENCODE); + if constexpr (store_values) { + if (!password_token_seen) { + if constexpr (result_type_is_ada_url) { + url.username += unicode::percent_encode( + authority_view, + character_sets::USERINFO_PERCENT_ENCODE); + } else { + url.append_base_username(unicode::percent_encode( + authority_view, + character_sets::USERINFO_PERCENT_ENCODE)); + } } else { - url.append_base_username(unicode::percent_encode( - authority_view.substr(0, password_token_location), - character_sets::USERINFO_PERCENT_ENCODE)); - url.append_base_password(unicode::percent_encode( - authority_view.substr(password_token_location + 1), - character_sets::USERINFO_PERCENT_ENCODE)); + if constexpr (result_type_is_ada_url) { + url.username += unicode::percent_encode( + authority_view.substr(0, password_token_location), + character_sets::USERINFO_PERCENT_ENCODE); + url.password += unicode::percent_encode( + authority_view.substr(password_token_location + 1), + character_sets::USERINFO_PERCENT_ENCODE); + } else { + url.append_base_username(unicode::percent_encode( + authority_view.substr(0, password_token_location), + character_sets::USERINFO_PERCENT_ENCODE)); + url.append_base_password(unicode::percent_encode( + authority_view.substr(password_token_location + 1), + character_sets::USERINFO_PERCENT_ENCODE)); + } } } - } else { + } else if constexpr (store_values) { if constexpr (result_type_is_ada_url) { url.password += unicode::percent_encode( authority_view, character_sets::USERINFO_PERCENT_ENCODE); @@ -12472,8 +12472,10 @@ result_type parse_url(std::string_view user_input, break; } if (end_of_authority == input_size) { - if (fragment.has_value()) { - url.update_unencoded_base_hash(*fragment); + if constexpr (store_values) { + if (fragment.has_value()) { + url.update_unencoded_base_hash(*fragment); + } } return url; } @@ -12670,19 +12672,22 @@ result_type parse_url(std::string_view user_input, } case ada::state::QUERY: { ada_log("QUERY ", helpers::substring(url_data, input_position)); - // Let queryPercentEncodeSet be the special-query percent-encode set if - // url is special; otherwise the query percent-encode set. - const uint8_t* query_percent_encode_set = - url.is_special() ? ada::character_sets::SPECIAL_QUERY_PERCENT_ENCODE - : ada::character_sets::QUERY_PERCENT_ENCODE; - - // Percent-encode after encoding, with encoding, buffer, and - // queryPercentEncodeSet, and append the result to url's query. - url.update_base_search(helpers::substring(url_data, input_position), - query_percent_encode_set); - ada_log("QUERY update_base_search completed "); - if (fragment.has_value()) { - url.update_unencoded_base_hash(*fragment); + if constexpr (store_values) { + // Let queryPercentEncodeSet be the special-query percent-encode set + // if url is special; otherwise the query percent-encode set. + const uint8_t* query_percent_encode_set = + url.is_special() + ? ada::character_sets::SPECIAL_QUERY_PERCENT_ENCODE + : ada::character_sets::QUERY_PERCENT_ENCODE; + + // Percent-encode after encoding, with encoding, buffer, and + // queryPercentEncodeSet, and append the result to url's query. + url.update_base_search(helpers::substring(url_data, input_position), + query_percent_encode_set); + ada_log("QUERY update_base_search completed "); + if (fragment.has_value()) { + url.update_unencoded_base_hash(*fragment); + } } return url; } @@ -12785,9 +12790,11 @@ result_type parse_url(std::string_view user_input, // Optimization: Avoiding going into PATH state improves the // performance of urls ending with /. if (input_position == input_size) { - url.update_base_pathname("/"); - if (fragment.has_value()) { - url.update_unencoded_base_hash(*fragment); + if constexpr (store_values) { + url.update_base_pathname("/"); + if (fragment.has_value()) { + url.update_unencoded_base_hash(*fragment); + } } return url; } @@ -12833,11 +12840,13 @@ result_type parse_url(std::string_view user_input, } else { input_position = input_size + 1; } - if constexpr (result_type_is_ada_url) { - helpers::parse_prepared_path(view, url.type, url.path); - } else { - url.consume_prepared_path(view); - ADA_ASSERT_TRUE(url.validate()); + if constexpr (store_values) { + if constexpr (result_type_is_ada_url) { + helpers::parse_prepared_path(view, url.type, url.path); + } else { + url.consume_prepared_path(view); + ADA_ASSERT_TRUE(url.validate()); + } } break; } @@ -13031,17 +13040,29 @@ result_type parse_url(std::string_view user_input, ada::unreachable(); } } - if (fragment.has_value()) { - url.update_unencoded_base_hash(*fragment); + if constexpr (store_values) { + if (fragment.has_value()) { + url.update_unencoded_base_hash(*fragment); + } } return url; } +template url parse_url_impl(std::string_view user_input, + const url* base_url = nullptr); +template url_aggregator parse_url_impl( + std::string_view user_input, const url_aggregator* base_url = nullptr); + +template +result_type parse_url(std::string_view user_input, + const result_type* base_url) { + return parse_url_impl(user_input, base_url); +} + template url parse_url(std::string_view user_input, const url* base_url = nullptr); template url_aggregator parse_url( std::string_view user_input, const url_aggregator* base_url = nullptr); - } // namespace ada::parser /* end file src/parser.cpp */ /* begin file src/url_components.cpp */ @@ -15397,6 +15418,15 @@ void ada_search_params_sort(ada_url_search_params result) { } } +void ada_search_params_reset(ada_url_search_params result, const char* input, + size_t length) { + ada::result& r = + *(ada::result*)result; + if (r) { + r->reset(std::string_view(input, length)); + } +} + void ada_search_params_append(ada_url_search_params result, const char* key, size_t key_length, const char* value, size_t value_length) { diff --git a/deps/ada/ada.h b/deps/ada/ada.h index 9142fbf66c8488..00ccd803505087 100644 --- a/deps/ada/ada.h +++ b/deps/ada/ada.h @@ -1,4 +1,4 @@ -/* auto-generated on 2024-05-30 22:24:57 -0400. Do not edit! */ +/* auto-generated on 2024-07-06 17:38:56 -0400. Do not edit! */ /* begin file include/ada.h */ /** * @file ada.h @@ -1855,6 +1855,9 @@ inline int fast_digit_count(uint32_t x) noexcept { #ifndef ADA_PARSER_H #define ADA_PARSER_H +#include +#include + /* begin file include/ada/expected.h */ /** * @file expected.h @@ -4377,9 +4380,6 @@ void swap(expected &lhs, #endif /* end file include/ada/expected.h */ -#include -#include - /** * @private */ @@ -4393,7 +4393,6 @@ struct url; * @brief Includes the definitions for supported parsers */ namespace ada::parser { - /** * Parses a url. The parameter user_input is the input to be parsed: * it should be a valid UTF-8 string. The parameter base_url is an optional @@ -4409,6 +4408,14 @@ extern template url_aggregator parse_url( extern template url parse_url(std::string_view user_input, const url* base_url); +template +result_type parse_url_impl(std::string_view user_input, + const result_type* base_url = nullptr); + +extern template url_aggregator parse_url_impl( + std::string_view user_input, const url_aggregator* base_url); +extern template url parse_url_impl(std::string_view user_input, + const url* base_url); } // namespace ada::parser #endif // ADA_PARSER_H @@ -4613,12 +4620,6 @@ namespace ada::unicode { bool to_ascii(std::optional& out, std::string_view plain, size_t first_percent); -/** - * @private - * @see https://www.unicode.org/reports/tr46/#ToUnicode - */ -std::string to_unicode(std::string_view input); - /** * @private * Checks if the input has tab or newline characters. @@ -4795,10 +4796,10 @@ constexpr bool to_lower_ascii(char* input, size_t length) noexcept; #ifndef ADA_URL_AGGREGATOR_H #define ADA_URL_AGGREGATOR_H - #include #include + namespace ada { /** @@ -4992,6 +4993,11 @@ struct url_aggregator : url_base { std::string_view, const ada::url_aggregator *); friend void ada::helpers::strip_trailing_spaces_from_opaque_path< ada::url_aggregator>(ada::url_aggregator &url) noexcept; + friend ada::url_aggregator ada::parser::parse_url_impl< + ada::url_aggregator, true>(std::string_view, const ada::url_aggregator *); + friend ada::url_aggregator + ada::parser::parse_url_impl( + std::string_view, const ada::url_aggregator *); std::string buffer{}; url_components components{}; @@ -5227,7 +5233,6 @@ ada_really_inline constexpr bool verify_dns_length( #ifndef ADA_URL_H #define ADA_URL_H - #include #include #include @@ -5235,6 +5240,7 @@ ada_really_inline constexpr bool verify_dns_length( #include #include + namespace ada { /** @@ -5509,6 +5515,11 @@ struct url : url_base { friend void ada::helpers::strip_trailing_spaces_from_opaque_path( ada::url &url) noexcept; + friend ada::url ada::parser::parse_url_impl(std::string_view, + const ada::url *); + friend ada::url_aggregator ada::parser::parse_url_impl< + ada::url_aggregator, true>(std::string_view, const ada::url_aggregator *); + inline void update_unencoded_base_hash(std::string_view input); inline void update_base_hostname(std::string_view input); inline void update_base_search(std::string_view input); @@ -6976,6 +6987,14 @@ struct url_search_params { inline auto back() const { return params.back(); } inline auto operator[](size_t index) const { return params[index]; } + /** + * @private + * Used to reset the search params to a new input. + * Used primarily for C API. + * @param input + */ + void reset(std::string_view input); + private: typedef std::pair key_value_pair; std::vector params{}; @@ -7046,6 +7065,11 @@ namespace ada { template url_search_params url_search_params_iter::EMPTY; +inline void url_search_params::reset(std::string_view input) { + params.clear(); + initialize(input); +} + inline void url_search_params::initialize(std::string_view input) { if (!input.empty() && input.front() == '?') { input.remove_prefix(1); @@ -7255,13 +7279,13 @@ url_search_params_entries_iter::next() { #ifndef ADA_ADA_VERSION_H #define ADA_ADA_VERSION_H -#define ADA_VERSION "2.8.0" +#define ADA_VERSION "2.9.0" namespace ada { enum { ADA_VERSION_MAJOR = 2, - ADA_VERSION_MINOR = 8, + ADA_VERSION_MINOR = 9, ADA_VERSION_REVISION = 0, }; diff --git a/deps/ada/ada_c.h b/deps/ada/ada_c.h index 173e27bb16af06..44e945c9656187 100644 --- a/deps/ada/ada_c.h +++ b/deps/ada/ada_c.h @@ -151,6 +151,8 @@ ada_string ada_search_params_get(ada_url_search_params result, const char* key, size_t key_length); ada_strings ada_search_params_get_all(ada_url_search_params result, const char* key, size_t key_length); +void ada_search_params_reset(ada_url_search_params result, const char* input, + size_t length); ada_url_search_params_keys_iter ada_search_params_get_keys( ada_url_search_params result); ada_url_search_params_values_iter ada_search_params_get_values( diff --git a/src/node_url.cc b/src/node_url.cc index c94537dd714e74..21f52c718a49a5 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -115,7 +115,7 @@ void BindingData::DomainToUnicode(const FunctionCallbackInfo& args) { if (!out->set_hostname(input)) { return args.GetReturnValue().Set(String::Empty(env->isolate())); } - std::string result = ada::unicode::to_unicode(out->get_hostname()); + std::string result = ada::idna::to_unicode(out->get_hostname()); args.GetReturnValue().Set(String::NewFromUtf8(env->isolate(), result.c_str(), @@ -499,7 +499,7 @@ std::optional FileURLToPath(Environment* env, // about percent encoding because the URL parser will have // already taken care of that for us. Note that this only // causes IDNs with an appropriate `xn--` prefix to be decoded. - return "\\\\" + ada::unicode::to_unicode(hostname) + decoded_pathname; + return "\\\\" + ada::idna::to_unicode(hostname) + decoded_pathname; } char letter = decoded_pathname[1] | 0x20;