diff options
author | Hannah von Reth <hannah.vonreth@owncloud.com> | 2021-07-29 12:48:31 +0300 |
---|---|---|
committer | Hannah von Reth <vonreth@kde.org> | 2021-07-29 19:15:28 +0300 |
commit | 2574ecd5a5f1242367f690b0b7c6c0bc674ab070 (patch) | |
tree | 126effff1161aa03636e8d3961d572f2be8b1287 /src | |
parent | 1be763213f6aa3a5f3bfc4819e7076439955c8fe (diff) |
Fix isChildPathOf
Diffstat (limited to 'src')
-rw-r--r-- | src/common/filesystembase.cpp | 13 | ||||
-rw-r--r-- | src/common/filesystembase.h | 5 |
2 files changed, 10 insertions, 8 deletions
diff --git a/src/common/filesystembase.cpp b/src/common/filesystembase.cpp index a4f99ccaa..b57b5d75e 100644 --- a/src/common/filesystembase.cpp +++ b/src/common/filesystembase.cpp @@ -535,15 +535,14 @@ QString FileSystem::pathtoUNC(const QString &_str) } #endif -bool FileSystem::isChildPathOf(QStringView child, QStringView parent) +bool FileSystem::isChildPathOf(const QString &child, const QString &parent) { - static const auto Casing = Utility::fsCasePreserving() ? Qt::CaseInsensitive : Qt::CaseSensitive; - // ignore additional / in the assert - Q_ASSERT(parent.startsWith(QFileInfo(parent.toString()).canonicalFilePath(), Casing)); - Q_ASSERT(child.startsWith(QFileInfo(child.toString()).canonicalFilePath(), Casing)); - return child.startsWith(parent, Casing); + // if it is a relative path assume a local file, resolve it based on root + const auto sensitivity = Utility::fsCaseSensitivity(); + return (child.startsWith(parent.endsWith(QLatin1Char('/')) ? parent : parent + QLatin1Char('/'), sensitivity) + // clear trailing slashes etc + || QString::compare(QDir::cleanPath(parent), QDir::cleanPath(child), sensitivity) == 0); } - } // namespace OCC #include "moc_filesystembase.cpp" diff --git a/src/common/filesystembase.h b/src/common/filesystembase.h index a7556240d..b4ace754c 100644 --- a/src/common/filesystembase.h +++ b/src/common/filesystembase.h @@ -164,7 +164,10 @@ namespace FileSystem { */ bool OCSYNC_EXPORT isJunction(const QString &filename); - bool OCSYNC_EXPORT isChildPathOf(QStringView child, QStringView parent); + /** + * Returns whether a Path is a child of another + */ + bool OCSYNC_EXPORT isChildPathOf(const QString &child, const QString &parent); } /** @} */ |