diff options
author | MacDue <macdue@dueutil.tech> | 2023-04-14 20:12:03 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-04-15 06:37:04 +0200 |
commit | 35612c6a7f7602ff46d56bbbbc8b33b28b411409 (patch) | |
tree | 772aabbc417980448cb50df548d8ff4c2ac18ca1 /Tests/AK/TestURL.cpp | |
parent | 5acd40c525a695b353dba348a95eb0cb314a33d5 (diff) | |
download | serenity-35612c6a7f7602ff46d56bbbbc8b33b28b411409.zip |
AK+Everywhere: Change URL::path() to serialize_path()
This now defaults to serializing the path with percent decoded segments
(which is what all callers expect), but has an option not to. This fixes
`file://` URLs with spaces in their paths.
The name has been changed to serialize_path() path to make it more clear
that this method will generate a new string each call (except for the
cannot_be_a_base_url() case). A few callers have then been updated to
avoid repeatedly calling this function.
Diffstat (limited to 'Tests/AK/TestURL.cpp')
-rw-r--r-- | Tests/AK/TestURL.cpp | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/Tests/AK/TestURL.cpp b/Tests/AK/TestURL.cpp index b0e5c453fb..c886b313f1 100644 --- a/Tests/AK/TestURL.cpp +++ b/Tests/AK/TestURL.cpp @@ -24,7 +24,7 @@ TEST_CASE(basic) EXPECT_EQ(url.scheme(), "http"); EXPECT_EQ(url.host(), "www.serenityos.org"); EXPECT_EQ(url.port_or_default(), 80); - EXPECT_EQ(url.path(), "/"); + EXPECT_EQ(url.serialize_path(), "/"); EXPECT(url.query().is_null()); EXPECT(url.fragment().is_null()); } @@ -34,7 +34,7 @@ TEST_CASE(basic) EXPECT_EQ(url.scheme(), "https"); EXPECT_EQ(url.host(), "www.serenityos.org"); EXPECT_EQ(url.port_or_default(), 443); - EXPECT_EQ(url.path(), "/index.html"); + EXPECT_EQ(url.serialize_path(), "/index.html"); EXPECT(url.query().is_null()); EXPECT(url.fragment().is_null()); } @@ -44,7 +44,7 @@ TEST_CASE(basic) EXPECT_EQ(url.scheme(), "https"); EXPECT_EQ(url.host(), "localhost"); EXPECT_EQ(url.port_or_default(), 1234); - EXPECT_EQ(url.path(), "/~anon/test/page.html"); + EXPECT_EQ(url.serialize_path(), "/~anon/test/page.html"); EXPECT(url.query().is_null()); EXPECT(url.fragment().is_null()); } @@ -54,7 +54,7 @@ TEST_CASE(basic) EXPECT_EQ(url.scheme(), "http"); EXPECT_EQ(url.host(), "www.serenityos.org"); EXPECT_EQ(url.port_or_default(), 80); - EXPECT_EQ(url.path(), "/index.html"); + EXPECT_EQ(url.serialize_path(), "/index.html"); EXPECT_EQ(url.query(), ""); EXPECT_EQ(url.fragment(), ""); } @@ -64,7 +64,7 @@ TEST_CASE(basic) EXPECT_EQ(url.scheme(), "http"); EXPECT_EQ(url.host(), "www.serenityos.org"); EXPECT_EQ(url.port_or_default(), 80); - EXPECT_EQ(url.path(), "/index.html"); + EXPECT_EQ(url.serialize_path(), "/index.html"); EXPECT_EQ(url.query(), "foo=1&bar=2"); EXPECT(url.fragment().is_null()); } @@ -74,7 +74,7 @@ TEST_CASE(basic) EXPECT_EQ(url.scheme(), "http"); EXPECT_EQ(url.host(), "www.serenityos.org"); EXPECT_EQ(url.port_or_default(), 80); - EXPECT_EQ(url.path(), "/index.html"); + EXPECT_EQ(url.serialize_path(), "/index.html"); EXPECT(url.query().is_null()); EXPECT_EQ(url.fragment(), "fragment"); } @@ -84,7 +84,7 @@ TEST_CASE(basic) EXPECT_EQ(url.scheme(), "http"); EXPECT_EQ(url.host(), "www.serenityos.org"); EXPECT_EQ(url.port_or_default(), 80); - EXPECT_EQ(url.path(), "/index.html"); + EXPECT_EQ(url.serialize_path(), "/index.html"); EXPECT_EQ(url.query(), "foo=1&bar=2&baz=/?"); EXPECT_EQ(url.fragment(), "frag/ment?test#"); } @@ -120,7 +120,7 @@ TEST_CASE(file_url_with_hostname) EXPECT_EQ(url.scheme(), "file"); EXPECT_EQ(url.host(), "courage"); EXPECT_EQ(url.port_or_default(), 0); - EXPECT_EQ(url.path(), "/my/file"); + EXPECT_EQ(url.serialize_path(), "/my/file"); EXPECT_EQ(url.serialize(), "file://courage/my/file"); EXPECT(url.query().is_null()); EXPECT(url.fragment().is_null()); @@ -132,7 +132,7 @@ TEST_CASE(file_url_with_localhost) EXPECT(url.is_valid()); EXPECT_EQ(url.scheme(), "file"); EXPECT_EQ(url.host(), ""); - EXPECT_EQ(url.path(), "/my/file"); + EXPECT_EQ(url.serialize_path(), "/my/file"); EXPECT_EQ(url.serialize(), "file:///my/file"); } @@ -142,7 +142,7 @@ TEST_CASE(file_url_without_hostname) EXPECT(url.is_valid()); EXPECT_EQ(url.scheme(), "file"); EXPECT_EQ(url.host(), ""); - EXPECT_EQ(url.path(), "/my/file"); + EXPECT_EQ(url.serialize_path(), "/my/file"); EXPECT_EQ(url.serialize(), "file:///my/file"); } @@ -151,7 +151,7 @@ TEST_CASE(file_url_with_encoded_characters) URL url("file:///my/file/test%23file.txt"sv); EXPECT(url.is_valid()); EXPECT_EQ(url.scheme(), "file"); - EXPECT_EQ(url.path(), "/my/file/test%23file.txt"); + EXPECT_EQ(url.serialize_path(), "/my/file/test#file.txt"); EXPECT(url.query().is_null()); EXPECT(url.fragment().is_null()); } @@ -161,7 +161,7 @@ TEST_CASE(file_url_with_fragment) URL url("file:///my/file#fragment"sv); EXPECT(url.is_valid()); EXPECT_EQ(url.scheme(), "file"); - EXPECT_EQ(url.path(), "/my/file"); + EXPECT_EQ(url.serialize_path(), "/my/file"); EXPECT(url.query().is_null()); EXPECT_EQ(url.fragment(), "fragment"); } @@ -171,7 +171,7 @@ TEST_CASE(file_url_with_root_path) URL url("file:///"sv); EXPECT(url.is_valid()); EXPECT_EQ(url.scheme(), "file"); - EXPECT_EQ(url.path(), "/"); + EXPECT_EQ(url.serialize_path(), "/"); } TEST_CASE(file_url_serialization) @@ -190,7 +190,7 @@ TEST_CASE(about_url) EXPECT(url.is_valid()); EXPECT_EQ(url.scheme(), "about"); EXPECT(url.host().is_null()); - EXPECT_EQ(url.path(), "blank"); + EXPECT_EQ(url.serialize_path(), "blank"); EXPECT(url.query().is_null()); EXPECT(url.fragment().is_null()); EXPECT_EQ(url.serialize(), "about:blank"); @@ -333,7 +333,7 @@ TEST_CASE(create_with_file_scheme) EXPECT_EQ(url.paths()[0], "home"); EXPECT_EQ(url.paths()[1], "anon"); EXPECT_EQ(url.paths()[2], "README.md"); - EXPECT_EQ(url.path(), "/home/anon/README.md"); + EXPECT_EQ(url.serialize_path(), "/home/anon/README.md"); EXPECT(url.query().is_null()); EXPECT(url.fragment().is_null()); @@ -343,10 +343,10 @@ TEST_CASE(create_with_file_scheme) EXPECT_EQ(url.paths()[0], "home"); EXPECT_EQ(url.paths()[1], "anon"); EXPECT_EQ(url.paths()[2], ""); - EXPECT_EQ(url.path(), "/home/anon/"); + EXPECT_EQ(url.serialize_path(), "/home/anon/"); url = URL("file:///home/anon/"sv); - EXPECT_EQ(url.path(), "/home/anon/"); + EXPECT_EQ(url.serialize_path(), "/home/anon/"); } TEST_CASE(complete_url) @@ -356,7 +356,7 @@ TEST_CASE(complete_url) EXPECT(url.is_valid()); EXPECT_EQ(url.scheme(), "http"); EXPECT_EQ(url.host(), "serenityos.org"); - EXPECT_EQ(url.path(), "/test.html"); + EXPECT_EQ(url.serialize_path(), "/test.html"); EXPECT(url.query().is_null()); EXPECT(url.query().is_null()); EXPECT_EQ(url.cannot_be_a_base_url(), false); @@ -389,7 +389,7 @@ TEST_CASE(unicode) { URL url { "http://example.com/_ünicöde_téxt_©"sv }; EXPECT(url.is_valid()); - EXPECT_EQ(url.path(), "/_%C3%BCnic%C3%B6de_t%C3%A9xt_%C2%A9"); + EXPECT_EQ(url.serialize_path(), "/_ünicöde_téxt_©"); EXPECT(url.query().is_null()); EXPECT(url.fragment().is_null()); } @@ -398,14 +398,14 @@ TEST_CASE(complete_file_url_with_base) { URL url { "file:///home/index.html" }; EXPECT(url.is_valid()); - EXPECT_EQ(url.path(), "/home/index.html"); + EXPECT_EQ(url.serialize_path(), "/home/index.html"); EXPECT_EQ(url.paths().size(), 2u); EXPECT_EQ(url.paths()[0], "home"); EXPECT_EQ(url.paths()[1], "index.html"); auto sub_url = url.complete_url("js/app.js"sv); EXPECT(sub_url.is_valid()); - EXPECT_EQ(sub_url.path(), "/home/js/app.js"); + EXPECT_EQ(sub_url.serialize_path(), "/home/js/app.js"); } TEST_CASE(empty_url_with_base_url) |