Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/ada/checkers-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ constexpr bool is_windows_drive_letter(std::string_view input) noexcept {

constexpr bool is_normalized_windows_drive_letter(
std::string_view input) noexcept {
return input.size() >= 2 && (is_alpha(input[0]) && (input[1] == ':'));
return input.size() == 2 && (is_alpha(input[0]) && (input[1] == ':'));
}

ada_really_inline constexpr uint64_t try_parse_ipv4_fast(
Expand Down
12 changes: 12 additions & 0 deletions tests/basic_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ TYPED_TEST(basic_tests, readme2) {
SUCCEED();
}

TYPED_TEST(basic_tests, file_shorten_path_normalized_drive_letter_only) {
// https://url.spec.whatwg.org/#shorten-a-urls-path : a file path's first
// segment is protected from ".." only when it is a *normalized Windows drive
// letter*, which is exactly two code points (an ASCII alpha followed by ":").
// Longer segments that merely start with "<alpha>:" must be popped.
ASSERT_EQ(ada::parse<TypeParam>("file:c:x/..")->get_href(), "file:///");
ASSERT_EQ(ada::parse<TypeParam>("file:u:p@h/..")->get_href(), "file:///");
// A real drive letter is still preserved.
ASSERT_EQ(ada::parse<TypeParam>("file:c:/..")->get_href(), "file:///c:/");
SUCCEED();
}

TYPED_TEST(basic_tests, readme2free) {
auto url = ada::parse("https://www.google.com");
url->set_username("username");
Expand Down
Loading