LexicalPath: Reset dirname if it's empty

dirname ends up empty if the canonical path only contains one element.

Reset it to the default for relative/absolute paths if that is the case.
This commit is contained in:
Tim Schumacher 2021-05-27 13:52:13 +02:00 committed by Ali Mohammad Pur
parent c906987651
commit 0aaa992c1c
Notes: sideshowbarker 2024-07-18 17:18:38 +09:00

View file

@ -68,6 +68,10 @@ void LexicalPath::canonicalize()
} }
m_dirname = dirname_builder.to_string(); m_dirname = dirname_builder.to_string();
if (m_dirname.is_empty()) {
m_dirname = m_is_absolute ? "/" : ".";
}
m_basename = canonical_parts.last(); m_basename = canonical_parts.last();
Optional<size_t> last_dot = StringView(m_basename).find_last_of('.'); Optional<size_t> last_dot = StringView(m_basename).find_last_of('.');