Skip to content

Commit

Permalink
Add and use the detail::is_posix_slash function
Browse files Browse the repository at this point in the history
  • Loading branch information
rmisev committed Aug 25, 2024
1 parent efabe2e commit a219398
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions include/upa/url.h
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,11 @@ constexpr bool is_slash(CharT ch) noexcept {
return ch == '/' || ch == '\\';
}

template <typename CharT>
constexpr bool is_posix_slash(CharT ch) noexcept {
return ch == '/';
}

template <typename CharT>
constexpr bool is_windows_slash(CharT ch) noexcept {
return ch == '\\' || ch == '/';
Expand Down Expand Up @@ -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<CharT>))
throw url_error(validation_errc::file_unsupported_path, "Unsupported file path");
// Absolute POSIX path
no_encode_set = &posix_path_no_encode_set;
Expand Down

0 comments on commit a219398

Please sign in to comment.