Utils: Adjust FilePath::relativePath()

When using the same path for the anchor and the relative path
we end up in an empty path which is conceptually wrong.
Especially when passing such a result directly without further
checking may lead to bad issues.
Return a path containing just the '.' (dot) instead.

Change-Id: I86e1ab91e6610831fc05bd81776d278e9fe10105
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: Jochen Becher <jochen_becher@gmx.de>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Stenger
2021-08-17 08:49:57 +02:00
parent fd0f6fd5e6
commit 28d2674b54
2 changed files with 12 additions and 6 deletions

View File

@@ -1043,6 +1043,8 @@ FilePath FilePath::relativePath(const FilePath &anchor) const
return {};
QString relativeFilePath = calcRelativePath(absolutePath, absoluteAnchorPath);
if (!filename.isEmpty()) {
if (relativeFilePath == ".")
relativeFilePath.clear();
if (!relativeFilePath.isEmpty())
relativeFilePath += '/';
relativeFilePath += filename;
@@ -1093,6 +1095,8 @@ QString FilePath::calcRelativePath(const QString &absolutePath, const QString &a
}
++i;
}
if (relativePath.isEmpty())
return QString(".");
return relativePath;
}