Enable parsing absolute Windows paths even if it starts with a slash (#1680)

In file URI when using absolute path on windows one has to write additional
'/' before the drive letter (empty host part). Eg: `file:///c:/windows/system32/`
`Path::parseWindows` throws an exception when using `URI::getPath()` to feed
it directly. The whole point of the commit to enable `/<DRIVE_LETTER>:` style
path as absolute path.
Test case added.
This commit is contained in:
csabakeszegh 2017-10-07 03:54:08 +02:00 committed by Aleksandar Fabijanic
parent ae8ccc4f48
commit 2113827719
3 changed files with 17 additions and 1 deletions

View File

@ -780,7 +780,7 @@ void Path::parseWindows(const std::string& path)
char d = *it++;
if (it != end && *it == ':') // drive letter
{
if (_absolute || !((d >= 'a' && d <= 'z') || (d >= 'A' && d <= 'Z'))) throw PathSyntaxException(path);
if (!((d >= 'a' && d <= 'z') || (d >= 'A' && d <= 'Z'))) throw PathSyntaxException(path);
_absolute = true;
_device += d;
++it;

View File

@ -858,6 +858,20 @@ void PathTest::testParseWindows4()
assert (p.toString(Path::PATH_WINDOWS) == "a\\b\\c\\d");
}
void PathTest::testParseWindows5()
{
Path p;
p.parse("/c:/windows/system32/", Path::PATH_WINDOWS);
assert(!p.isRelative());
assert(p.isAbsolute());
assert(p.getDevice() == "c");
assert(p.depth() == 2);
assert(p[0] == "windows");
assert(p[1] == "system32");
assert(p.isDirectory());
assert(!p.isFile());
assert(p.toString(Path::PATH_WINDOWS) == "c:\\windows\\system32\\");
}
void PathTest::testParseVMS1()
{
@ -1670,6 +1684,7 @@ CppUnit::Test* PathTest::suite()
CppUnit_addTest(pSuite, PathTest, testParseWindows2);
CppUnit_addTest(pSuite, PathTest, testParseWindows3);
CppUnit_addTest(pSuite, PathTest, testParseWindows4);
CppUnit_addTest(pSuite, PathTest, testParseWindows5);
CppUnit_addTest(pSuite, PathTest, testParseVMS1);
CppUnit_addTest(pSuite, PathTest, testParseVMS2);
CppUnit_addTest(pSuite, PathTest, testParseVMS3);

View File

@ -34,6 +34,7 @@ public:
void testParseWindows2();
void testParseWindows3();
void testParseWindows4();
void testParseWindows5();
void testParseVMS1();
void testParseVMS2();
void testParseVMS3();