Created
March 24, 2014 00:08
-
-
Save Amanieu/9731900 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/engine/framework/FileSystem.cpp b/src/engine/framework/FileSystem.cpp | |
index 84b8a0b..4622773 100644 | |
--- a/src/engine/framework/FileSystem.cpp | |
+++ b/src/engine/framework/FileSystem.cpp | |
@@ -648,27 +648,26 @@ namespace Path { | |
bool IsValid(Str::StringRef path, bool allowDir) | |
{ | |
- bool nonAlphaNum = true; | |
+ char prev = '/'; | |
for (char c: path) { | |
- // Always allow alphanumeric characters | |
- if (Str::cisalnum(c)) { | |
- nonAlphaNum = false; | |
- continue; | |
- } | |
- | |
- // Don't allow 2 consecutive punctuation characters | |
- if (nonAlphaNum) | |
+ // Check if the character is allowed | |
+ if (!Str::cisalnum(c) && c != '/' && c != '-' && c != '_' && c != '.' && c != '+' && c != '~') | |
return false; | |
- // Only allow the following punctuation characters | |
- if (c != '/' && c != '-' && c != '_' && c != '.' && c != '+' && c != '~') | |
+ // Disallow 2 consecutive / or . | |
+ if ((c == '/' || c == '.') && (prev == '/' || prev == '.')) | |
return false; | |
- nonAlphaNum = true; | |
+ | |
+ prev = c; | |
} | |
// An empty path or a path ending with / is a directory | |
- if (nonAlphaNum) | |
- return allowDir && (path.empty() || path.back() == '/'); | |
+ if (prev == '/' && !allowDir) | |
+ return false; | |
+ | |
+ // Disallow paths ending with . | |
+ if (prev == '.') | |
+ return false; | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment