| 16067 | } |
| 16068 | |
| 16069 | tl::expected<std::string, errors> canonicalize_protocol( |
| 16070 | std::string_view input) { |
| 16071 | ada_log("canonicalize_protocol called with input=", input); |
| 16072 | // If value is the empty string, return value. |
| 16073 | if (input.empty()) [[unlikely]] { |
| 16074 | return ""; |
| 16075 | } |
| 16076 | |
| 16077 | // IMPORTANT: Deviation from the spec. We remove the trailing ':' here. |
| 16078 | if (input.ends_with(":")) { |
| 16079 | input.remove_suffix(1); |
| 16080 | } |
| 16081 | |
| 16082 | // Let dummyURL be a new URL record. |
| 16083 | // Let parseResult be the result of running the basic URL parser given value |
| 16084 | // followed by "://dummy.test", with dummyURL as url. |
| 16085 | if (auto dummy_url = ada::parse<url_aggregator>( |
| 16086 | std::string(input) + "://dummy.test", nullptr)) { |
| 16087 | // IMPORTANT: Deviation from the spec. We remove the trailing ':' here. |
| 16088 | // Since URL parser always return protocols ending with `:` |
| 16089 | auto protocol = dummy_url->get_protocol(); |
| 16090 | protocol.remove_suffix(1); |
| 16091 | return std::string(protocol); |
| 16092 | } |
| 16093 | // If parseResult is failure, then throw a TypeError. |
| 16094 | return tl::unexpected(errors::type_error); |
| 16095 | } |
| 16096 | |
| 16097 | tl::expected<std::string, errors> canonicalize_username( |
| 16098 | std::string_view input) { |
no test coverage detected