util: Fix FilePath::isValid() and add tests (#908)

* fixed bug that caused FilePath to be invalid for files with extension
* added tests for FilePath::isValid()
fixes #907
This commit is contained in:
Malte Langkabel
2020-02-13 00:29:15 +01:00
committed by GitHub
parent 3be685dbc9
commit db95591645
2 changed files with 29 additions and 7 deletions
+5 -7
View File
@@ -115,17 +115,19 @@ bool FilePath::isAbsolute() const
bool FilePath::isValid() const
{
boost::filesystem::path::iterator end = m_path->end();
if (!isDirectory())
{
if (!boost::filesystem::portable_file_name(m_path->filename().generic_string()))
{
return false;
}
end--;
}
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();
@@ -136,14 +138,10 @@ bool FilePath::isValid() const
it++;
}
}
#else
return true; // FIXME: hot fix for issue #907
#endif
for (; it != m_path->end(); ++it)
for (; it != end; ++it)
{
std::string ss = it->string();
if (!boost::filesystem::portable_directory_name(ss))
if (!boost::filesystem::portable_directory_name(it->string()))
{
return false;
}