From d3947d0ad5177a96a90044370ec7d2062d4de360 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 14 Jul 2022 18:15:58 +0200 Subject: [PATCH] fs/Path: GetExtension() skips all leading dots Don't return an empty string for "..", because this path doesn't have an extension. --- src/fs/Path.cxx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/fs/Path.cxx b/src/fs/Path.cxx index 86a6fe7f8..6c427a4c9 100644 --- a/src/fs/Path.cxx +++ b/src/fs/Path.cxx @@ -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;