fs/Path: GetExtension() skips all leading dots

Don't return an empty string for "..", because this path doesn't have
an extension.
This commit is contained in:
Max Kellermann 2022-07-14 18:15:58 +02:00
parent 849ed122c7
commit d3947d0ad5

View File

@ -39,9 +39,15 @@ Path::ToUTF8Throw() const
Path::const_pointer
Path::GetExtension() const noexcept
{
const auto base = GetBase().c_str();
const auto *base = GetBase().c_str();
/* skip all leading dots (hidden/special files on UNIX-like
operating systems) */
while (*base == '.')
++base;
const auto *dot = StringFindLast(base, '.');
if (dot == nullptr || dot == base)
if (dot == nullptr)
return nullptr;
return dot + 1;