From f82564f05b15033e57bb338089b0e7ce59d1c7e9 Mon Sep 17 00:00:00 2001 From: Robin Linden Date: Sun, 17 Dec 2023 22:45:31 +0100 Subject: [PATCH] url: Drop the default error-handler --- url/BUILD | 1 - url/url.cpp | 30 +++++------------------------- url/url.h | 2 +- 3 files changed, 6 insertions(+), 27 deletions(-) diff --git a/url/BUILD b/url/BUILD index 3bcbe5e97..6a87fc52a 100644 --- a/url/BUILD +++ b/url/BUILD @@ -39,7 +39,6 @@ cc_library( "//util:unicode", "//util:uuid", "@icu//:common", - "@spdlog", ], ) diff --git a/url/url.cpp b/url/url.cpp index 678d1e804..17efa1cd8 100644 --- a/url/url.cpp +++ b/url/url.cpp @@ -11,7 +11,6 @@ #include "util/unicode.h" #include "util/uuid.h" -#include #include #include #include @@ -25,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -295,23 +295,15 @@ Origin Url::origin() const { } void UrlParser::validation_error(ValidationError err) const { - on_error_(err); + if (on_error_) { + on_error_(err); + } } std::string_view description(ValidationError e) { return validation_error_str.at(e); } -UrlParser::UrlParser() : util::BaseParser("") { - set_on_error([this](ValidationError e) { - spdlog::warn("url: InputPos: {}, ParserState: {}, Validation Error: {} {}", - current_pos(), - std::to_underlying(state_), - std::to_underlying(e), - description(e)); - }); -} - // https://url.spec.whatwg.org/#concept-url-parser std::optional UrlParser::parse(std::string input, std::optional base) { if (input.empty() && !base.has_value()) { @@ -843,8 +835,6 @@ void UrlParser::state_port() { auto res = std::from_chars(buffer_.data(), buffer_.data() + buffer_.size(), port); if (res.ec == std::errc::invalid_argument || res.ec == std::errc::result_out_of_range) { - spdlog::info("Invalid port given in URL"); - state_ = ParserState::Failure; return; @@ -1180,9 +1170,7 @@ std::optional UrlParser::domain_to_ascii(std::string_view domain, b auto *uts = icu::IDNA::createUTS46Instance(opts, err); if (U_FAILURE(err)) { - spdlog::info("Failed to create UTS46 instance, error {}; idna data probably missing from icu", - static_cast(err)); - + std::cerr << "Failed to create UTS46 instance: " << u_errorName(err) << '\n' << std::flush; return std::nullopt; } @@ -1444,15 +1432,11 @@ std::optional> UrlParser::parse_ipv4_number(std: auto res = std::from_chars(input.data(), input.data() + input.size(), out, r); if (res.ec == std::errc::invalid_argument) { - spdlog::info("Invalid IPv4 number"); - return std::nullopt; } // This deviation from the spec is necessary, because the spec assumes arbitrary precision if (res.ec == std::errc::result_out_of_range) { - spdlog::info("IPv4 number > 2^64"); - // The number returned here is an error value return {{-1, true}}; } @@ -1516,8 +1500,6 @@ std::optional> UrlParser::parse_ipv6(std::string_vi auto res = std::from_chars(input.data() + pointer, input.data() + pointer + 1, out, 16); if (res.ec == std::errc::invalid_argument || res.ec == std::errc::result_out_of_range) { - spdlog::info("Invalid IPv6 input"); - return std::nullopt; } @@ -1566,8 +1548,6 @@ std::optional> UrlParser::parse_ipv6(std::string_vi auto res = std::from_chars(input.data() + pointer, input.data() + pointer + 1, number); if (res.ec == std::errc::invalid_argument || res.ec == std::errc::result_out_of_range) { - spdlog::info("Invalid IPv6 input 2"); - return std::nullopt; } diff --git a/url/url.h b/url/url.h index f292a801b..15e45b3b1 100644 --- a/url/url.h +++ b/url/url.h @@ -149,7 +149,7 @@ std::string_view description(ValidationError); // This parser is current with the WHATWG URL specification as of 27 September 2023 class UrlParser final : util::BaseParser { public: - UrlParser(); + UrlParser() : util::BaseParser("") {} std::optional parse(std::string input, std::optional base = std::nullopt);