| 16130 | } |
| 16131 | |
| 16132 | tl::expected<std::string, errors> canonicalize_hostname( |
| 16133 | std::string_view input) { |
| 16134 | ada_log("canonicalize_hostname input=", input); |
| 16135 | // If value is the empty string, return value. |
| 16136 | if (input.empty()) [[unlikely]] { |
| 16137 | return ""; |
| 16138 | } |
| 16139 | // Let dummyURL be a new URL record. |
| 16140 | // Let parseResult be the result of running the basic URL parser given value |
| 16141 | // with dummyURL as url and hostname state as state override. |
| 16142 | |
| 16143 | // IMPORTANT: The protocol needs to be a special protocol, otherwise the |
| 16144 | // hostname will not be converted using IDNA. |
| 16145 | auto url = ada::parse<url_aggregator>("https://dummy.test", nullptr); |
| 16146 | ADA_ASSERT_TRUE(url); |
| 16147 | // if (!isValidHostnameInput(hostname)) return kj::none; |
| 16148 | if (!url->set_hostname(input)) { |
| 16149 | // If parseResult is failure, then throw a TypeError. |
| 16150 | return tl::unexpected(errors::type_error); |
| 16151 | } |
| 16152 | // Return dummyURL's host, serialized, or empty string if it is null. |
| 16153 | return std::string(url->get_hostname()); |
| 16154 | } |
| 16155 | |
| 16156 | tl::expected<std::string, errors> canonicalize_ipv6_hostname( |
| 16157 | std::string_view input) { |
no test coverage detected