forked from qt-creator/qt-creator
Fix FilePath::absoluteFilePath for default constructed file path
FilePath::absoluteFilePath() would consider an empty path to be relative, and resolved it wrt the current working directory. That is unexpected in the sense that QFileInfo::absoluteFilePath behaves differently, and lead to a crash down the line when e.g. a diff editor was opened when the current working directory is '/' (the default on macOS when started with "open" or from Finder, Dock or Spotlight). Make FilePath::absoluteFilePath() return and empty path if the input was empty. Change-Id: Ie0d4da50afa24134bd56505b2f4abcf382eee982 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -721,7 +721,11 @@ FilePath FilePath::parentDir() const
|
||||
|
||||
FilePath FilePath::absolutePath() const
|
||||
{
|
||||
const FilePath parentPath = isAbsolutePath() ? parentDir() : FilePath::currentWorkingPath().resolvePath(*this).parentDir();
|
||||
if (!needsDevice() && isEmpty())
|
||||
return *this;
|
||||
const FilePath parentPath = isAbsolutePath()
|
||||
? parentDir()
|
||||
: FilePath::currentWorkingPath().resolvePath(*this).parentDir();
|
||||
return parentPath.isEmpty() ? *this : parentPath;
|
||||
}
|
||||
|
||||
@@ -729,6 +733,8 @@ FilePath FilePath::absoluteFilePath() const
|
||||
{
|
||||
if (isAbsolutePath())
|
||||
return *this;
|
||||
if (!needsDevice() && isEmpty())
|
||||
return *this;
|
||||
|
||||
return FilePath::currentWorkingPath().resolvePath(*this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user