Fixed isValidPathComponent() to detect invalid chars or reserved names.

This commit is contained in:
Vincent Richard 2005-03-28 09:47:34 +00:00
parent 9bc3121e2d
commit 1673ecc41e

View File

@ -92,7 +92,50 @@ const vmime::string windowsFileSystemFactory::pathToStringImpl(const vmime::util
const bool windowsFileSystemFactory::isValidPathComponent(const vmime::utility::file::path::component& comp) const
{
return (comp.getBuffer().find_first_of("\\*") == vmime::string::npos);
const string& buffer = comp.getBuffer();
// Check for invalid characters
for (string::size_type i = 0 ; i < buffer.length() ; ++i)
{
const unsigned char c = buffer[i];
switch (c)
{
// Reserved characters
case '<': case '>': case ':':
case '"': case '/': case '\\':
case '|': case '$': case '*':
return false;
default:
if (c <= 31)
return false;
}
}
// Check for reserved names
if (buffer.length() == 3)
{
if (buffer == "CON" || buffer == "PRN" || buffer == "AUX" || buffer == "NUL")
return false;
}
else if (buffer.length() == 4)
{
if (buffer[0] == 'C' && buffer[1] == 'O' && // COM1-COM9
buffer[2] == 'M' && (buffer[3] >= '0' && buffer[3] <= '9'))
{
return false;
}
else if (buffer[0] == 'L' && buffer[1] == 'P' && // LPT1-LPT9
buffer[2] == 'T' && (buffer[3] >= '0' && buffer[3] <= '9'))
{
return false;
}
}
return true;
}