logic: fix crash when project directory contains non-latin character (issue #899) (#901)

* added "isValid()" to FilePath
* used "isValid" in check of selected project directory
This commit is contained in:
Malte Langkabel
2020-01-27 21:52:05 +01:00
committed by GitHub
parent 719591a247
commit 8cc4aaf6ea
3 changed files with 63 additions and 5 deletions
+41 -3
View File
@@ -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());
@@ -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');
}
+1
View File
@@ -31,6 +31,7 @@ public:
bool recheckExists() const;
bool isDirectory() const;
bool isAbsolute() const;
bool isValid() const;
FilePath getParentDirectory() const;
@@ -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;
}