Modified isValidPathComponent() to accept drives as first component.
This commit is contained in:
parent
eb8e3842fc
commit
0b37c6d09c
@ -23,6 +23,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "vmime/exception.hpp"
|
#include "vmime/exception.hpp"
|
||||||
|
#include "vmime/utility/stringUtils.hpp"
|
||||||
|
|
||||||
|
|
||||||
#if VMIME_HAVE_FILESYSTEM_FEATURES
|
#if VMIME_HAVE_FILESYSTEM_FEATURES
|
||||||
@ -89,11 +90,25 @@ const vmime::string windowsFileSystemFactory::pathToStringImpl(const vmime::util
|
|||||||
return (native);
|
return (native);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const bool windowsFileSystemFactory::isValidPathComponent(const vmime::utility::file::path::component& comp) const
|
const bool windowsFileSystemFactory::isValidPathComponent(const vmime::utility::file::path::component& comp) const
|
||||||
|
{
|
||||||
|
return isValidPathComponent(comp, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool windowsFileSystemFactory::isValidPathComponent(
|
||||||
|
const vmime::utility::file::path::component& comp,
|
||||||
|
bool firstComponent) const
|
||||||
{
|
{
|
||||||
const string& buffer = comp.getBuffer();
|
const string& buffer = comp.getBuffer();
|
||||||
|
|
||||||
|
// If first component, check if component is a drive
|
||||||
|
if (firstComponent && (buffer.length() == 2) && (buffer[1] == ':'))
|
||||||
|
{
|
||||||
|
char drive = tolower(buffer[0]);
|
||||||
|
if ((drive >= 'a') && (drive <= 'z'))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Check for invalid characters
|
// Check for invalid characters
|
||||||
for (string::size_type i = 0 ; i < buffer.length() ; ++i)
|
for (string::size_type i = 0 ; i < buffer.length() ; ++i)
|
||||||
{
|
{
|
||||||
@ -115,26 +130,27 @@ const bool windowsFileSystemFactory::isValidPathComponent(const vmime::utility::
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string upperBuffer = vmime::utility::stringUtils::toUpper(buffer);
|
||||||
|
|
||||||
// Check for reserved names
|
// Check for reserved names
|
||||||
if (buffer.length() == 3)
|
if (upperBuffer.length() == 3)
|
||||||
{
|
{
|
||||||
if (buffer == "CON" || buffer == "PRN" || buffer == "AUX" || buffer == "NUL")
|
if (upperBuffer == "CON" || buffer == "PRN" || buffer == "AUX" || buffer == "NUL")
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (buffer.length() == 4)
|
else if (upperBuffer.length() == 4)
|
||||||
{
|
{
|
||||||
if (buffer[0] == 'C' && buffer[1] == 'O' && // COM1-COM9
|
if ((upperBuffer.substr(0, 3) == "COM") && // COM0 to COM9
|
||||||
buffer[2] == 'M' && (buffer[3] >= '0' && buffer[3] <= '9'))
|
(upperBuffer[3] >= '0') && (upperBuffer[3] <= '9'))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (buffer[0] == 'L' && buffer[1] == 'P' && // LPT1-LPT9
|
else if ((upperBuffer.substr(0, 3) == "LPT") && // LPT0 to LPT9
|
||||||
buffer[2] == 'T' && (buffer[3] >= '0' && buffer[3] <= '9'))
|
(upperBuffer[3] >= '0') && (upperBuffer[3] <= '9'))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +159,7 @@ const bool windowsFileSystemFactory::isValidPath(const vmime::utility::file::pat
|
|||||||
{
|
{
|
||||||
for (int i = 0 ; i < path.getSize() ; ++i)
|
for (int i = 0 ; i < path.getSize() ; ++i)
|
||||||
{
|
{
|
||||||
if (!isValidPathComponent(path[i]))
|
if (!isValidPathComponent(path[i], (i==0)))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +46,8 @@ public:
|
|||||||
static const vmime::string pathToStringImpl(const vmime::utility::file::path& path);
|
static const vmime::string pathToStringImpl(const vmime::utility::file::path& path);
|
||||||
|
|
||||||
const bool isValidPathComponent(const vmime::utility::file::path::component& comp) const;
|
const bool isValidPathComponent(const vmime::utility::file::path::component& comp) const;
|
||||||
|
const bool isValidPathComponent(const vmime::utility::file::path::component& comp,
|
||||||
|
bool firstComponent) const;
|
||||||
const bool isValidPath(const vmime::utility::file::path& path) const;
|
const bool isValidPath(const vmime::utility::file::path& path) const;
|
||||||
|
|
||||||
static void reportError(const vmime::utility::path& path, const int err);
|
static void reportError(const vmime::utility::path& path, const int err);
|
||||||
|
Loading…
Reference in New Issue
Block a user