From a21939853a3c426dcdaf40b40d28a2d05a107275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rimas=20Misevi=C4=8Dius?= Date: Sun, 25 Aug 2024 14:54:13 +0300 Subject: [PATCH] Add and use the `detail::is_posix_slash` function --- include/upa/url.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/upa/url.h b/include/upa/url.h index 15cd095..b6cefd7 100644 --- a/include/upa/url.h +++ b/include/upa/url.h @@ -983,6 +983,11 @@ constexpr bool is_slash(CharT ch) noexcept { return ch == '/' || ch == '\\'; } +template +constexpr bool is_posix_slash(CharT ch) noexcept { + return ch == '/'; +} + template constexpr bool is_windows_slash(CharT ch) noexcept { return ch == '\\' || ch == '/'; @@ -3180,9 +3185,9 @@ inline url url_from_file_path(StrT&& str, file_path_format format = file_path_fo std::string str_url("file://"); if (format == file_path_format::posix) { - if (*first != '/') + if (!detail::is_posix_slash(*first)) throw url_error(validation_errc::file_unsupported_path, "Non-absolute POSIX path"); - if (detail::has_dot_dot_segment(start_of_check, last, [](CharT c) { return c == '/'; })) + if (detail::has_dot_dot_segment(start_of_check, last, detail::is_posix_slash)) throw url_error(validation_errc::file_unsupported_path, "Unsupported file path"); // Absolute POSIX path no_encode_set = &posix_path_no_encode_set;