mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Make LexicalPath handle relative paths correctly
Previously LexicalPath would consider "." and ".." as equivalent to "/". This is not true though.
This commit is contained in:
parent
ebb1d9740e
commit
c99fd217e2
Notes:
sideshowbarker
2024-07-18 17:53:03 +09:00
Author: https://github.com/gunnarbeutner Commit: https://github.com/SerenityOS/serenity/commit/c99fd217e23 Pull-request: https://github.com/SerenityOS/serenity/pull/7237
2 changed files with 5 additions and 1 deletions
|
@ -55,7 +55,7 @@ void LexicalPath::canonicalize()
|
|||
}
|
||||
}
|
||||
if (canonical_parts.is_empty()) {
|
||||
m_string = m_basename = m_dirname = "/";
|
||||
m_string = m_basename = m_dirname = m_is_absolute ? "/" : ".";
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,12 +24,16 @@ TEST_CASE(basic)
|
|||
EXPECT_EQ(path.parts().size(), 3u);
|
||||
EXPECT_EQ(path.parts(), Vector<String>({ "abc", "def", "ghi.txt" }));
|
||||
EXPECT_EQ(path.string(), "/abc/def/ghi.txt");
|
||||
EXPECT_EQ(LexicalPath(".").string(), ".");
|
||||
EXPECT_EQ(LexicalPath("..").string(), "..");
|
||||
}
|
||||
|
||||
TEST_CASE(dotdot_coalescing)
|
||||
{
|
||||
EXPECT_EQ(LexicalPath("/home/user/../../not/home").string(), "/not/home");
|
||||
EXPECT_EQ(LexicalPath("/../../../../").string(), "/");
|
||||
EXPECT_EQ(LexicalPath("./../../../../").string(), "../../../..");
|
||||
EXPECT_EQ(LexicalPath("../../../../../").string(), "../../../../..");
|
||||
}
|
||||
|
||||
TEST_CASE(has_extension)
|
||||
|
|
Loading…
Reference in a new issue