| 16229 | } |
| 16230 | |
| 16231 | tl::expected<std::string, errors> canonicalize_pathname( |
| 16232 | std::string_view input) { |
| 16233 | // If value is the empty string, then return value. |
| 16234 | if (input.empty()) [[unlikely]] { |
| 16235 | return ""; |
| 16236 | } |
| 16237 | // Let leading slash be true if the first code point in value is U+002F (/) |
| 16238 | // and otherwise false. |
| 16239 | const bool leading_slash = input.starts_with("/"); |
| 16240 | // Let modified value be "/-" if leading slash is false and otherwise the |
| 16241 | // empty string. |
| 16242 | const auto modified_value = leading_slash ? "" : "/-"; |
| 16243 | const auto full_url = |
| 16244 | std::string("fake://fake-url") + modified_value + std::string(input); |
| 16245 | if (auto url = ada::parse<url_aggregator>(full_url, nullptr)) { |
| 16246 | const auto pathname = url->get_pathname(); |
| 16247 | // If leading slash is false, then set result to the code point substring |
| 16248 | // from 2 to the end of the string within result. |
| 16249 | return leading_slash ? std::string(pathname) |
| 16250 | : std::string(pathname.substr(2)); |
| 16251 | } |
| 16252 | // If parseResult is failure, then throw a TypeError. |
| 16253 | return tl::unexpected(errors::type_error); |
| 16254 | } |
| 16255 | |
| 16256 | tl::expected<std::string, errors> canonicalize_opaque_pathname( |
| 16257 | std::string_view input) { |
no test coverage detected