From 15c30e0d00a59d6f986107c6e8d23fad3380b7c7 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sat, 21 May 2011 23:40:44 -0400 Subject: [PATCH] fix Engine::validatePath() to accept a const ref --- src/Engine.cc | 21 +++++++-------------- src/Engine.h | 2 +- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/Engine.cc b/src/Engine.cc index d8b9185..6c7d59e 100644 --- a/src/Engine.cc +++ b/src/Engine.cc @@ -249,24 +249,17 @@ void Engine::checkForAllHandlerFunctions() checkForFunction("mouse_motion_event", mouse_motion); } -bool Engine::validatePath(string & path) +bool Engine::validatePath(const string & path) { - if (path.find_first_not_of(FILENAME_SAFE_CHARS) != string::npos) + if (path[0] == '/') return false; - if (path[0] == ':') - return false; - vector parts = split(path, ':'); - path = ""; - bool multiple = false; + vector parts = split(path, '/'); for (int i = 0, sz = parts.size(); i < sz; i++) { - if (parts[i].find_first_not_of(".") != string::npos) - { - if (multiple) - path += "/"; - path += parts[i]; - multiple = true; - } + if (parts[i].find_first_not_of(FILENAME_SAFE_CHARS) != string::npos) + return false; + if (parts[i].find_first_not_of(".") == string::npos) + return false; } return true; } diff --git a/src/Engine.h b/src/Engine.h index 055feec..060c8d4 100644 --- a/src/Engine.h +++ b/src/Engine.h @@ -324,7 +324,7 @@ class Engine m_av.setCursorVisible( m_engine_cursor_visible || m_script_cursor_visible); } - bool validatePath(std::string & path); + bool validatePath(const std::string & path); int getFileSize(const char *fname); AV & m_av;