Skip to content

Commit

Permalink
deps: update ada to 1.0.3
Browse files Browse the repository at this point in the history
PR-URL: #46784
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Tierney Cyren <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
nodejs-github-bot authored and targos committed Mar 13, 2023
1 parent 4e0b932 commit 4e18e0a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 95 deletions.
141 changes: 49 additions & 92 deletions deps/ada/ada.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* auto-generated on 2023-02-07 17:26:54 -0500. Do not edit! */
/* auto-generated on 2023-02-22 14:24:01 -0500. Do not edit! */
// dofile: invoked with prepath=/Users/yagiz/Developer/url-parser/src, filename=ada.cpp
/* begin file src/ada.cpp */
#include "ada.h"
Expand Down Expand Up @@ -635,33 +635,37 @@ namespace ada::serializers {
}

std::string ipv6(const std::array<uint16_t, 8>& address) noexcept {
size_t compress_length = 0;
size_t compress = 0;
size_t compress_length = 0; // The length of a long sequence of zeros.
size_t compress = 0; // The start of a long sequence of zeros.
find_longest_sequence_of_ipv6_pieces(address, compress, compress_length);

if (compress_length <= 1) {
// Optimization opportunity: Find a faster way then snprintf for imploding and return here.
compress = compress_length = 8;
}

std::string output{};
std::string output(4 * 8 + 7 + 2, '\0');
size_t piece_index = 0;
char buf[5];

char *point = output.data();
char *point_end = output.data() + output.size();
*point++ = '[';
while (true) {
if (piece_index == compress) {
output.append("::", piece_index == 0 ? 2 : 1);
if ((piece_index = piece_index + compress_length) == 8) break;
*point++ = ':';
// If we skip a value initially, we need to write '::', otherwise
// a single ':' will do since it follows a previous ':'.
if(piece_index == 0) { *point++ = ':'; }
piece_index += compress_length;
if(piece_index == 8) { break; }
}

// Optimization opportunity: Get rid of snprintf.
snprintf(buf, 5, "%x", address[piece_index]);
output += buf;
if (++piece_index == 8) break;
output.push_back(':');
point = std::to_chars(point, point_end, address[piece_index], 16).ptr;
piece_index++;
if(piece_index == 8) { break; }
*point++ = ':';
}

return "[" + output + "]";
*point++ = ']';
output.resize(point - output.data());
return output;
}

std::string ipv4(const uint64_t address) noexcept {
Expand Down Expand Up @@ -1651,7 +1655,16 @@ namespace ada {
if (trimmed.empty()) { port = std::nullopt; return true; }
// Input should not start with control characters.
if (ada::unicode::is_c0_control_or_space(trimmed.front())) { return false; }
return parse_port(trimmed);
// Input should contain at least one ascii digit.
if (input.find_first_of("0123456789") == std::string_view::npos) { return false; }

// Revert changes if parse_port fails.
std::optional<uint16_t> previous_port = port;
parse_port(trimmed);
if (is_valid) { return true; }
port = previous_port;
is_valid = true;
return false;
}

void url::set_hash(const std::string_view input) {
Expand Down Expand Up @@ -1692,7 +1705,7 @@ namespace ada {
return parse_path(input);
}

bool url::set_host(const std::string_view input) {
bool url::set_host_or_hostname(const std::string_view input, bool override_hostname) {
if (has_opaque_path) { return false; }

std::optional<std::string> previous_host = host;
Expand All @@ -1713,7 +1726,7 @@ namespace ada {
// Otherwise, if c is U+003A (:) and insideBrackets is false, then:
// Note: we cannot access *pointer safely if (pointer == pointer_end).
if ((pointer != new_host.end()) && (*pointer == ':') && !inside_brackets) {
// TODO: The next 2 lines is the only difference between set_host and set_hostname. Let's simplify it.
if (override_hostname) { return false; }
std::string_view buffer(&*(pointer + 1));
if (!buffer.empty()) { set_port(buffer); }
}
Expand Down Expand Up @@ -1761,70 +1774,12 @@ namespace ada {
return true;
}

bool url::set_hostname(const std::string_view input) {
if (has_opaque_path) { return false; }

std::optional<std::string> previous_host = host;

std::string_view::iterator input_pointer_end = std::find(input.begin(), input.end(), '#');
std::string _host(input.data(), std::distance(input.begin(), input_pointer_end));
helpers::remove_ascii_tab_or_newline(_host);
std::string_view new_host(_host);

// If url's scheme is "file", then set state to file host state, instead of host state.
if (get_scheme_type() != ada::scheme::type::FILE) {
std::string_view host_view(_host.data(), _host.length());
bool inside_brackets{false};
size_t location = helpers::get_host_delimiter_location(*this, host_view, inside_brackets);
std::string_view::iterator pointer = (location != std::string_view::npos) ? new_host.begin() + location : new_host.end();

// Otherwise, if c is U+003A (:) and insideBrackets is false, then:
// Note: we cannot access *pointer safely if (pointer == pointer_end).
if ((pointer != new_host.end()) && (*pointer == ':') && !inside_brackets) {
// If buffer is the empty string, validation error, return failure.
return false;
}
// If url is special and host_view is the empty string, validation error, return failure.
else if (host_view.empty() && is_special()) {
return false;
}
// Otherwise, if state override is given, host_view is the empty string,
// and either url includes credentials or url’s port is non-null, return.
else if (host_view.empty() && (includes_credentials() || port.has_value())) {
return true;
}

// Let host be the result of host parsing host_view with url is not special.
if (host_view.empty()) {
host = "";
return true;
}

bool succeeded = parse_host(host_view);
if (!succeeded) { host = previous_host; }
return succeeded;
}

size_t location = new_host.find_first_of("/\\?");
if (location != std::string_view::npos) { new_host.remove_suffix(new_host.length() - location); }

if (new_host.empty()) {
// Set url’s host to the empty string.
host = "";
}
else {
// Let host be the result of host parsing buffer with url is not special.
if (!parse_host(new_host)) {
host = previous_host;
return false;
}
bool url::set_host(const std::string_view input) {
return set_host_or_hostname(input, false);
}

// If host is "localhost", then set host to the empty string.
if (host.has_value() && host.value() == "localhost") {
host = "";
}
}
return true;
bool url::set_hostname(const std::string_view input) {
return set_host_or_hostname(input, true);
}

bool url::set_protocol(const std::string_view input) {
Expand All @@ -1849,15 +1804,16 @@ namespace ada {
ada::result out = ada::parse(input);

if (out) {
set_protocol(out->get_protocol());
set_username(out->get_username());
set_password(out->get_password());
set_host(out->get_host());
set_hostname(out->get_hostname());
set_port(out->get_port());
set_pathname(out->get_pathname());
set_hash(out->get_hash());
set_search(out->get_search());
username = out->username;
password = out->password;
host = out->host;
port = out->port;
path = out->path;
query = out->query;
fragment = out->fragment;
type = out->type;
non_special_scheme = out->non_special_scheme;
has_opaque_path = out->has_opaque_path;
}

return out.has_value();
Expand Down Expand Up @@ -1989,7 +1945,8 @@ namespace ada::parser {
case ada::state::NO_SCHEME: {
ada_log("NO_SCHEME ", helpers::substring(url_data, input_position));
// If base is null, or base has an opaque path and c is not U+0023 (#), validation error, return failure.
if (base_url == nullptr || (base_url->has_opaque_path && (input_position != input_size))) {
// SCHEME state updates the state to NO_SCHEME and validates url_data is not empty.
if (base_url == nullptr || (base_url->has_opaque_path && url_data[input_position] != '#')) {
ada_log("NO_SCHEME validation error");
url.is_valid = false;
return url;
Expand Down
15 changes: 12 additions & 3 deletions deps/ada/ada.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* auto-generated on 2023-02-07 17:26:54 -0500. Do not edit! */
/* auto-generated on 2023-02-22 14:24:01 -0500. Do not edit! */
// dofile: invoked with prepath=/Users/yagiz/Developer/url-parser/include, filename=ada.h
/* begin file include/ada.h */
/**
Expand Down Expand Up @@ -1453,6 +1453,15 @@ namespace ada {
*/
bool set_href(const std::string_view input);

/**
* @private
*
* Sets the host or hostname according to override condition.
* Return true on success.
* @see https://url.spec.whatwg.org/#hostname-state
*/
bool set_host_or_hostname(std::string_view input, bool override_hostname);

/**
* The password getter steps are to return this’s URL’s password.
* @see https://url.spec.whatwg.org/#dom-url-password
Expand Down Expand Up @@ -4333,14 +4342,14 @@ namespace ada {
#ifndef ADA_ADA_VERSION_H
#define ADA_ADA_VERSION_H

#define ADA_VERSION "1.0.1"
#define ADA_VERSION "1.0.3"

namespace ada {

enum {
ADA_VERSION_MAJOR = 1,
ADA_VERSION_MINOR = 0,
ADA_VERSION_REVISION = 1,
ADA_VERSION_REVISION = 3,
};

} // namespace ada
Expand Down

0 comments on commit 4e18e0a

Please sign in to comment.