diff options
Diffstat (limited to 'src/utils/paths.cpp')
-rw-r--r-- | src/utils/paths.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp index 8decb6e95..04f553ca9 100644 --- a/src/utils/paths.cpp +++ b/src/utils/paths.cpp @@ -20,10 +20,12 @@ #include "utils/paths.h" +#include "utils/stringutils.h" + #include <string.h> #include <cstdarg> #include <cstdio> - +#include <physfs.h> #include <stdlib.h> #ifdef WIN32 @@ -55,3 +57,21 @@ bool isRealPath(const std::string &str) std::string path = getRealPath(str); return str == path; } + +bool checkPath(std::string path) +{ + if (path.empty()) + return true; + return path.find("../") == std::string::npos + && path.find("..\\") == std::string::npos + && path.find("/..") == std::string::npos + && path.find("\\..") == std::string::npos; +} + +std::string &fixDirSeparators(std::string &str) +{ + if (*PHYSFS_getDirSeparator() == '/') + return str; + + return replaceAll(str, "/", "\\"); +} |