fix Engine::validatePath() to accept a const ref

This commit is contained in:
Josh Holtrop 2011-05-21 23:40:44 -04:00
parent 67010e02c2
commit 15c30e0d00
2 changed files with 8 additions and 15 deletions

View File

@ -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<string> parts = split(path, ':');
path = "";
bool multiple = false;
vector<string> 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;
}

View File

@ -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;