From 2924c1c9480043d4ae46bddd4e8b74cda1f997d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eberhard=20Gr=C3=A4ther?= Date: Fri, 3 Apr 2020 15:27:31 +0200 Subject: [PATCH] logic: Less restrictions for FilePath::isValid check on project location (#959) Switch from using boost::filesystem::portable_name and boost::filesystem::portable_directory_name to using boost::filesystem::windows_name, which allows periods and spaces in paths. Fixes #957 --- src/lib/utility/file/FilePath.cpp | 15 ++------------- src/test/FilePathTestSuite.cpp | 12 ++++++++++++ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/lib/utility/file/FilePath.cpp b/src/lib/utility/file/FilePath.cpp index bab3c33a..955159d3 100644 --- a/src/lib/utility/file/FilePath.cpp +++ b/src/lib/utility/file/FilePath.cpp @@ -115,17 +115,6 @@ 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 (isAbsolute() && m_path->has_root_path()) @@ -139,9 +128,9 @@ bool FilePath::isValid() const } } - for (; it != end; ++it) + for (; it != m_path->end(); ++it) { - if (!boost::filesystem::portable_directory_name(it->string())) + if (!boost::filesystem::windows_name(it->string())) { return false; } diff --git a/src/test/FilePathTestSuite.cpp b/src/test/FilePathTestSuite.cpp index 586ccf15..69ebe0db 100644 --- a/src/test/FilePathTestSuite.cpp +++ b/src/test/FilePathTestSuite.cpp @@ -215,8 +215,14 @@ TEST_CASE("file path is valid for absolute and relative existing files and direc { REQUIRE(FilePath(L"data/FilePathTestSuite/a.cpp").isValid()); REQUIRE(FilePath(L"data/FilePathTestSuite/a.cpp").makeAbsolute().isValid()); + REQUIRE(FilePath(L"data/FilePathTestSuite/with space/s.srctrlprj").isValid()); + REQUIRE(FilePath(L"data/FilePathTestSuite/with space/s.srctrlprj").makeAbsolute().isValid()); REQUIRE(FilePath(L"data/FilePathTestSuite").isValid()); REQUIRE(FilePath(L"data/FilePathTestSuite").makeAbsolute().isValid()); + REQUIRE(FilePath(L"data/FilePathTestSuite/container.app").isValid()); + REQUIRE(FilePath(L"data/FilePathTestSuite/container.app").makeAbsolute().isValid()); + REQUIRE(FilePath(L"data/FilePathTestSuite/container.app/b.txt").isValid()); + REQUIRE(FilePath(L"data/FilePathTestSuite/container.app/b.txt").makeAbsolute().isValid()); } TEST_CASE("file path is valid for absolute and relative non-existing files and directories paths") @@ -225,6 +231,10 @@ TEST_CASE("file path is valid for absolute and relative non-existing files and d REQUIRE(FilePath(L"data/non-existing-file.cpp").makeAbsolute().isValid()); REQUIRE(FilePath(L"data/non-existing-dir").isValid()); REQUIRE(FilePath(L"data/non-existing-dir").makeAbsolute().isValid()); + REQUIRE(FilePath(L"data/FilePathTestSuite/container.app/c.txt").isValid()); + REQUIRE(FilePath(L"data/FilePathTestSuite/container.app/c.txt").makeAbsolute().isValid()); + REQUIRE(FilePath(L"data/FilePathTestSuite/also space").isValid()); + REQUIRE(FilePath(L"data/FilePathTestSuite/also space").makeAbsolute().isValid()); } TEST_CASE("file path is invalid for absolute and relative paths with invalid characters") @@ -233,4 +243,6 @@ TEST_CASE("file path is invalid for absolute and relative paths with invalid cha REQUIRE(!FilePath(L"data/non-exis\"ting-file.cpp").makeAbsolute().isValid()); REQUIRE(!FilePath(L"data/non-exis|ting-dir").isValid()); REQUIRE(!FilePath(L"data/non-exis|ting-dir").makeAbsolute().isValid()); + REQUIRE(!FilePath(L"data/FilePathTestSuite/container:app").isValid()); + REQUIRE(!FilePath(L"data/FilePathTestSuite/container:app").makeAbsolute().isValid()); }