Skip to content

Commit

Permalink
url: Expose ValidationError descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
robinlinden committed Dec 17, 2023
1 parent 8cc56c5 commit afa01b3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion url/url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
}

Expand Down
2 changes: 2 additions & 0 deletions url/url.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions url/url_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit afa01b3

Please sign in to comment.