forked from qt-creator/qt-creator
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user