srctree

Robin Linden parent 8cc56c5c dd8da78f
url: Expose ValidationError descriptions

inlinesplit
url/url.cpp added: 14, removed: 4, total 10
@@ -298,13 +298,17 @@ void UrlParser::validation_error(ValidationError err) const {
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),
validation_error_str.at(e));
description(e));
});
}
 
 
url/url.h added: 14, removed: 4, total 10
@@ -144,6 +144,8 @@ enum class ValidationError {
FileInvalidWindowsDriveLetterHost
};
 
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:
 
url/url_test.cpp added: 14, removed: 4, total 10
@@ -74,6 +74,10 @@ int main() {
blob, std::regex("blob:https://\\[2001:db8:85a3::8a2e:370:7334\\]:8080/" + regex_uuid)));
});
 
etest::test("Validation error: description", [] {
etest::expect(!description(url::ValidationError::DomainInvalidCodePoint).empty()); //
});
 
etest::test("URL parsing: port and path", [] {
url::UrlParser p;