Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
logic: fix crash when project directory contains non-latin character …
Browse files Browse the repository at this point in the history
…(issue #899) (#901)

* added "isValid()" to FilePath
* used "isValid" in check of selected project directory
  • Loading branch information
mlangkabel authored Jan 27, 2020
1 parent 719591a commit 8cc4aaf
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
44 changes: 41 additions & 3 deletions src/lib/utility/file/FilePath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,43 @@ bool FilePath::isAbsolute() const
return m_path->is_absolute();
}

bool FilePath::isValid() const
{
if (!isDirectory())
{
if (!boost::filesystem::portable_file_name(m_path->filename().generic_string()))
{
return false;
}
}

boost::filesystem::path::iterator it = m_path->begin();

#if WIN32
if (isAbsolute() && m_path->has_root_path())
{
std::string root = m_path->root_path().string();
std::string current = "";
while (current.size() < root.size())
{
current += it->string();
it++;
}
}
#endif

for (; it != m_path->end(); ++it)
{
std::string ss = it->string();
if (!boost::filesystem::portable_directory_name(ss))
{
return false;
}
}

return true;
}

FilePath FilePath::getParentDirectory() const
{
FilePath parentDirectory(m_path->parent_path().wstring());
Expand Down Expand Up @@ -182,9 +219,10 @@ FilePath& FilePath::makeCanonical()
boost::filesystem::path symlink = boost::filesystem::read_symlink(canonicalPath);
if (!symlink.empty())
{
// on Windows the read_symlink function discards the drive letter (this is a boost
// bug). Therefore we need to make the path absolute again. We also have to discard
// the trailing \0 characters so that we can continue appending to the path.
// on Windows the read_symlink function discards the drive letter (this is a
// boost bug). Therefore we need to make the path absolute again. We also have
// to discard the trailing \0 characters so that we can continue appending to
// the path.
canonicalPath = utility::substrBeforeFirst(
boost::filesystem::absolute(symlink).string(), '\0');
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/utility/file/FilePath.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class FilePath
bool recheckExists() const;
bool isDirectory() const;
bool isAbsolute() const;
bool isValid() const;

FilePath getParentDirectory() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,30 @@ bool QtProjectWizardContentProjectData::check()

std::vector<FilePath> paths =
FilePath(m_projectFileLocation->getText().toStdWString()).expandEnvironmentVariables();
if (paths.size() != 1 || !paths[0].isAbsolute())
if (paths.size() != 1)
{
QMessageBox msgBox;
msgBox.setText(
"The specified location is invalid. Please enter an absolute directory path.");
"The specified location seems to be invalid. Please make sure that the used "
"environment variables are unambiguous.");
msgBox.exec();
return false;
}
else if (!paths.front().isAbsolute())
{
QMessageBox msgBox;
msgBox.setText(
"The specified location seems to be invalid. Please specify an absolute directory "
"path.");
msgBox.exec();
return false;
}
else if (!paths.front().isValid())
{
QMessageBox msgBox;
msgBox.setText(
"The specified location seems to be invalid. Please check the characters used in the "
"path.");
msgBox.exec();
return false;
}
Expand Down

0 comments on commit 8cc4aaf

Please sign in to comment.