Skip to content
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

have better ubsan stack trace #816

Closed
wants to merge 1 commit into from
Closed
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
26 changes: 13 additions & 13 deletions include/ada/implementation-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ parse_url_pattern(std::variant<std::string_view, url_pattern_init> input,
// Set init to the result of running parse a constructor string given input.
auto parse_result = url_pattern_helpers::constructor_string_parser::parse(
std::get<std::string_view>(input));
if (!parse_result) {
if (!parse_result.has_value()) {
ada_log("constructor_string_parser::parse failed");
return tl::unexpected(parse_result.error());
}
Expand Down Expand Up @@ -53,7 +53,7 @@ parse_url_pattern(std::variant<std::string_view, url_pattern_init> input,
auto processed_init = url_pattern_init::process(
init, "pattern", std::nullopt, std::nullopt, std::nullopt, std::nullopt,
std::nullopt, std::nullopt, std::nullopt, std::nullopt);
if (!processed_init) {
if (!processed_init.has_value()) {
ada_log("url_pattern_init::process failed for init and 'pattern'");
return tl::unexpected(processed_init.error());
}
Expand Down Expand Up @@ -103,7 +103,7 @@ parse_url_pattern(std::variant<std::string_view, url_pattern_init> input,
processed_init->protocol.value(),
url_pattern_helpers::canonicalize_protocol,
url_pattern_compile_component_options::DEFAULT);
if (!protocol_component) {
if (!protocol_component.has_value()) {
ada_log("url_pattern_component::compile failed for protocol ",
processed_init->protocol.value());
return tl::unexpected(protocol_component.error());
Expand All @@ -117,7 +117,7 @@ parse_url_pattern(std::variant<std::string_view, url_pattern_init> input,
processed_init->username.value(),
url_pattern_helpers::canonicalize_username,
url_pattern_compile_component_options::DEFAULT);
if (!username_component) {
if (!username_component.has_value()) {
ada_log("url_pattern_component::compile failed for username ",
processed_init->username.value());
return tl::unexpected(username_component.error());
Expand All @@ -131,7 +131,7 @@ parse_url_pattern(std::variant<std::string_view, url_pattern_init> input,
processed_init->password.value(),
url_pattern_helpers::canonicalize_password,
url_pattern_compile_component_options::DEFAULT);
if (!password_component) {
if (!password_component.has_value()) {
ada_log("url_pattern_component::compile failed for password ",
processed_init->password.value());
return tl::unexpected(password_component.error());
Expand All @@ -153,7 +153,7 @@ parse_url_pattern(std::variant<std::string_view, url_pattern_init> input,
processed_init->hostname.value(),
url_pattern_helpers::canonicalize_ipv6_hostname,
url_pattern_compile_component_options::DEFAULT);
if (!hostname_component) {
if (!hostname_component.has_value()) {
ada_log("url_pattern_component::compile failed for ipv6 hostname ",
processed_init->hostname.value());
return tl::unexpected(hostname_component.error());
Expand All @@ -167,7 +167,7 @@ parse_url_pattern(std::variant<std::string_view, url_pattern_init> input,
processed_init->hostname.value(),
url_pattern_helpers::canonicalize_hostname,
url_pattern_compile_component_options::HOSTNAME);
if (!hostname_component) {
if (!hostname_component.has_value()) {
ada_log("url_pattern_component::compile failed for hostname ",
processed_init->hostname.value());
return tl::unexpected(hostname_component.error());
Expand All @@ -180,7 +180,7 @@ parse_url_pattern(std::variant<std::string_view, url_pattern_init> input,
auto port_component = url_pattern_component::compile(
processed_init->port.value(), url_pattern_helpers::canonicalize_port,
url_pattern_compile_component_options::DEFAULT);
if (!port_component) {
if (!port_component.has_value()) {
ada_log("url_pattern_component::compile failed for port ",
processed_init->port.value());
return tl::unexpected(port_component.error());
Expand All @@ -190,7 +190,7 @@ parse_url_pattern(std::variant<std::string_view, url_pattern_init> input,
// Let compileOptions be a copy of the default options with the ignore case
// property set to options["ignoreCase"].
auto compile_options = url_pattern_compile_component_options::DEFAULT;
if (options) {
if (options != nullptr) {
compile_options.ignore_case = options->ignore_case;
}

Expand All @@ -212,7 +212,7 @@ parse_url_pattern(std::variant<std::string_view, url_pattern_init> input,
auto pathname_component = url_pattern_component::compile(
processed_init->pathname.value(),
url_pattern_helpers::canonicalize_pathname, path_compile_options);
if (!pathname_component) {
if (!pathname_component.has_value()) {
ada_log("url_pattern_component::compile failed for pathname ",
processed_init->pathname.value());
return tl::unexpected(pathname_component.error());
Expand All @@ -225,7 +225,7 @@ parse_url_pattern(std::variant<std::string_view, url_pattern_init> input,
auto pathname_component = url_pattern_component::compile(
processed_init->pathname.value(),
url_pattern_helpers::canonicalize_opaque_pathname, compile_options);
if (!pathname_component) {
if (!pathname_component.has_value()) {
ada_log("url_pattern_component::compile failed for opaque pathname ",
processed_init->pathname.value());
return tl::unexpected(pathname_component.error());
Expand All @@ -238,7 +238,7 @@ parse_url_pattern(std::variant<std::string_view, url_pattern_init> input,
auto search_component = url_pattern_component::compile(
processed_init->search.value(), url_pattern_helpers::canonicalize_search,
compile_options);
if (!search_component) {
if (!search_component.has_value()) {
ada_log("url_pattern_component::compile failed for search ",
processed_init->search.value());
return tl::unexpected(search_component.error());
Expand All @@ -250,7 +250,7 @@ parse_url_pattern(std::variant<std::string_view, url_pattern_init> input,
auto hash_component = url_pattern_component::compile(
processed_init->hash.value(), url_pattern_helpers::canonicalize_hash,
compile_options);
if (!hash_component) {
if (!hash_component.has_value()) {
ada_log("url_pattern_component::compile failed for hash ",
processed_init->hash.value());
return tl::unexpected(hash_component.error());
Expand Down
32 changes: 16 additions & 16 deletions include/ada/url_pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ enum class url_pattern_part_modifier : uint8_t {
class url_pattern_part {
public:
url_pattern_part(url_pattern_part_type _type, std::string&& _value,
url_pattern_part_modifier _modifier)
url_pattern_part_modifier _modifier) noexcept
: type(_type), value(_value), modifier(_modifier) {}

url_pattern_part(url_pattern_part_type _type, std::string&& _value,
url_pattern_part_modifier _modifier, std::string&& _name,
std::string&& _prefix, std::string&& _suffix)
std::string&& _prefix, std::string&& _suffix) noexcept
: type(_type),
value(_value),
modifier(_modifier),
Expand All @@ -159,10 +159,10 @@ class url_pattern_part {

// @see https://urlpattern.spec.whatwg.org/#options-header
struct url_pattern_compile_component_options {
url_pattern_compile_component_options() = default;
url_pattern_compile_component_options() noexcept = default;
explicit url_pattern_compile_component_options(
std::optional<char> new_delimiter = std::nullopt,
std::optional<char> new_prefix = std::nullopt)
std::optional<char> new_prefix = std::nullopt) noexcept
: delimiter(new_delimiter), prefix(new_prefix) {}

std::string_view get_delimiter() const ada_warn_unused;
Expand All @@ -188,25 +188,25 @@ struct url_pattern_compile_component_options {
// URLPatternComponentResult API is defined as part of the URLPattern
// specification.
struct url_pattern_component_result {
std::string input;
std::unordered_map<std::string, std::string> groups;
std::string input{};
std::unordered_map<std::string, std::string> groups{};
};

class url_pattern_component {
public:
url_pattern_component() = default;
url_pattern_component() noexcept = default;

// This function explicitly takes a std::string because it is moved.
// To avoid unnecessary copy, move each value while calling the constructor.
url_pattern_component(std::string_view new_pattern, std::regex&& new_regexp,
url_pattern_component(std::string&& new_pattern, std::regex&& new_regexp,
std::regex_constants::syntax_option_type new_flags,
std::vector<std::string>&& new_group_name_list,
bool new_has_regexp_groups)
: regexp(new_regexp),
bool new_has_regexp_groups) noexcept
: has_regexp_groups(new_has_regexp_groups),
regexp(new_regexp),
group_name_list(std::move(new_group_name_list)),
pattern(std::move(new_pattern)),
flags(new_flags),
group_name_list(new_group_name_list),
has_regexp_groups(new_has_regexp_groups) {}
flags(new_flags) {}

// @see https://urlpattern.spec.whatwg.org/#compile-a-component
template <url_pattern_encoding_callback F>
Expand All @@ -220,11 +220,11 @@ class url_pattern_component {

std::string to_string() const;

bool has_regexp_groups{false};
std::regex regexp{};
std::string pattern{};
std::regex_constants::syntax_option_type flags = std::regex::ECMAScript;
std::vector<std::string> group_name_list{};
bool has_regexp_groups = false;
std::string pattern{};
std::regex_constants::syntax_option_type flags{std::regex::ECMAScript};
};

using url_pattern_input = std::variant<url_aggregator, url_pattern_init>;
Expand Down
5 changes: 3 additions & 2 deletions include/ada/url_pattern_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class url_pattern_parser {
// @see https://urlpattern.spec.whatwg.org/#is-a-duplicate-name
bool is_duplicate_name(std::string_view name);

std::vector<Token> tokens{};
F encoding_callback;
std::string segment_wildcard_regexp;
std::vector<Token> tokens{};
std::vector<url_pattern_part> parts{};
std::string pending_fixed_value{};
size_t index = 0;
Expand Down Expand Up @@ -136,7 +136,8 @@ class Tokenizer {
};

// @see https://urlpattern.spec.whatwg.org/#constructor-string-parser
struct constructor_string_parser {
class constructor_string_parser {
public:
explicit constructor_string_parser(std::string_view new_input,
std::vector<Token>&& new_token_list)
: input(new_input), token_list(std::move(new_token_list)) {}
Expand Down
24 changes: 12 additions & 12 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ tl::expected<url_pattern, url_pattern_errors> parse_url_pattern_impl(
// Set init to the result of running parse a constructor string given input.
auto parse_result = url_pattern_helpers::constructor_string_parser::parse(
std::get<std::string_view>(input));
if (!parse_result) {
if (!parse_result.has_value()) {
ada_log("constructor_string_parser::parse failed");
return tl::unexpected(parse_result.error());
}
Expand Down Expand Up @@ -945,7 +945,7 @@ tl::expected<url_pattern, url_pattern_errors> parse_url_pattern_impl(
auto processed_init = url_pattern_init::process(
init, "pattern", std::nullopt, std::nullopt, std::nullopt, std::nullopt,
std::nullopt, std::nullopt, std::nullopt, std::nullopt);
if (!processed_init) {
if (!processed_init.has_value()) {
ada_log("url_pattern_init::process failed for init and 'pattern'");
return tl::unexpected(processed_init.error());
}
Expand Down Expand Up @@ -995,7 +995,7 @@ tl::expected<url_pattern, url_pattern_errors> parse_url_pattern_impl(
processed_init->protocol.value(),
url_pattern_helpers::canonicalize_protocol,
url_pattern_compile_component_options::DEFAULT);
if (!protocol_component) {
if (!protocol_component.has_value()) {
ada_log("url_pattern_component::compile failed for protocol ",
processed_init->protocol.value());
return tl::unexpected(protocol_component.error());
Expand All @@ -1009,7 +1009,7 @@ tl::expected<url_pattern, url_pattern_errors> parse_url_pattern_impl(
processed_init->username.value(),
url_pattern_helpers::canonicalize_username,
url_pattern_compile_component_options::DEFAULT);
if (!username_component) {
if (!username_component.has_value()) {
ada_log("url_pattern_component::compile failed for username ",
processed_init->username.value());
return tl::unexpected(username_component.error());
Expand All @@ -1023,7 +1023,7 @@ tl::expected<url_pattern, url_pattern_errors> parse_url_pattern_impl(
processed_init->password.value(),
url_pattern_helpers::canonicalize_password,
url_pattern_compile_component_options::DEFAULT);
if (!password_component) {
if (!password_component.has_value()) {
ada_log("url_pattern_component::compile failed for password ",
processed_init->password.value());
return tl::unexpected(password_component.error());
Expand All @@ -1045,7 +1045,7 @@ tl::expected<url_pattern, url_pattern_errors> parse_url_pattern_impl(
processed_init->hostname.value(),
url_pattern_helpers::canonicalize_ipv6_hostname,
url_pattern_compile_component_options::DEFAULT);
if (!hostname_component) {
if (!hostname_component.has_value()) {
ada_log("url_pattern_component::compile failed for ipv6 hostname ",
processed_init->hostname.value());
return tl::unexpected(hostname_component.error());
Expand All @@ -1059,7 +1059,7 @@ tl::expected<url_pattern, url_pattern_errors> parse_url_pattern_impl(
processed_init->hostname.value(),
url_pattern_helpers::canonicalize_hostname,
url_pattern_compile_component_options::HOSTNAME);
if (!hostname_component) {
if (!hostname_component.has_value()) {
ada_log("url_pattern_component::compile failed for hostname ",
processed_init->hostname.value());
return tl::unexpected(hostname_component.error());
Expand All @@ -1072,7 +1072,7 @@ tl::expected<url_pattern, url_pattern_errors> parse_url_pattern_impl(
auto port_component = url_pattern_component::compile(
processed_init->port.value(), url_pattern_helpers::canonicalize_port,
url_pattern_compile_component_options::DEFAULT);
if (!port_component) {
if (!port_component.has_value()) {
ada_log("url_pattern_component::compile failed for port ",
processed_init->port.value());
return tl::unexpected(port_component.error());
Expand Down Expand Up @@ -1104,7 +1104,7 @@ tl::expected<url_pattern, url_pattern_errors> parse_url_pattern_impl(
auto pathname_component = url_pattern_component::compile(
processed_init->pathname.value(),
url_pattern_helpers::canonicalize_pathname, path_compile_options);
if (!pathname_component) {
if (!pathname_component.has_value()) {
ada_log("url_pattern_component::compile failed for pathname ",
processed_init->pathname.value());
return tl::unexpected(pathname_component.error());
Expand All @@ -1117,7 +1117,7 @@ tl::expected<url_pattern, url_pattern_errors> parse_url_pattern_impl(
auto pathname_component = url_pattern_component::compile(
processed_init->pathname.value(),
url_pattern_helpers::canonicalize_opaque_pathname, compile_options);
if (!pathname_component) {
if (!pathname_component.has_value()) {
ada_log("url_pattern_component::compile failed for opaque pathname ",
processed_init->pathname.value());
return tl::unexpected(pathname_component.error());
Expand All @@ -1130,7 +1130,7 @@ tl::expected<url_pattern, url_pattern_errors> parse_url_pattern_impl(
auto search_component = url_pattern_component::compile(
processed_init->search.value(), url_pattern_helpers::canonicalize_search,
compile_options);
if (!search_component) {
if (!search_component.has_value()) {
ada_log("url_pattern_component::compile failed for search ",
processed_init->search.value());
return tl::unexpected(search_component.error());
Expand All @@ -1142,7 +1142,7 @@ tl::expected<url_pattern, url_pattern_errors> parse_url_pattern_impl(
auto hash_component = url_pattern_component::compile(
processed_init->hash.value(), url_pattern_helpers::canonicalize_hash,
compile_options);
if (!hash_component) {
if (!hash_component.has_value()) {
ada_log("url_pattern_component::compile failed for hash ",
processed_init->hash.value());
return tl::unexpected(hash_component.error());
Expand Down
Loading
Loading