diff --git a/pdal/util/FileUtils.cpp b/pdal/util/FileUtils.cpp index 7ca17e3bc6..fb06ea0ed4 100644 --- a/pdal/util/FileUtils.cpp +++ b/pdal/util/FileUtils.cpp @@ -79,6 +79,11 @@ namespace FileUtils std::istream *openFile(std::string const& filename, bool asBinary) { + std::string::size_type found_tilde(std::string::npos); + found_tilde = filename.find('~'); + if (found_tilde != std::string::npos) + throw pdal::pdal_error("PDAL does not support shell expansion"); + std::ifstream *ifs = nullptr; std::string name(filename); @@ -371,7 +376,15 @@ std::string extension(const std::string& filename) std::vector glob(std::string path) { std::vector filenames; + + #ifdef WIN32 + + std::string::size_type found_tilde(std::string::npos); + found_tilde = path.find('~'); + if (found_tilde != std::string::npos) + throw pdal::pdal_error("PDAL does not support shell expansion"); + WIN32_FIND_DATA ffd; HANDLE handle = FindFirstFile(path.c_str(), &ffd); diff --git a/test/unit/FileUtilsTest.cpp b/test/unit/FileUtilsTest.cpp index a634b3e173..92a2934ebb 100644 --- a/test/unit/FileUtilsTest.cpp +++ b/test/unit/FileUtilsTest.cpp @@ -75,6 +75,8 @@ TEST(FileUtilsTest, test_file_ops) // delete test FileUtils::deleteFile(tmp2); EXPECT_TRUE(FileUtils::fileExists(tmp2)==false); + + EXPECT_THROW(FileUtils::openFile("~foo1.glob"), pdal::pdal_error); } TEST(FileUtilsTest, test_readFileIntoString) @@ -242,6 +244,10 @@ TEST(FileUtilsTest, glob) EXPECT_EQ(FileUtils::glob(TP("*.glob")).size(), 0u); EXPECT_EQ(FileUtils::glob(TP("foo1.glob")).size(), 0u); +#ifdef _WIN32 + EXPECT_THROW(FileUtils::glob(TP("~foo1.glob")), pdal::pdal_error); +#endif + FileUtils::deleteFile("temp.glob"); FileUtils::closeFile(FileUtils::createFile("temp.glob")); EXPECT_EQ(FileUtils::glob("temp.glob").size(), 1u);