From 211382771982f98af028351036295072efc07880 Mon Sep 17 00:00:00 2001 From: csabakeszegh Date: Sat, 7 Oct 2017 03:54:08 +0200 Subject: [PATCH] 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 `/:` style path as absolute path. Test case added. --- Foundation/src/Path.cpp | 2 +- Foundation/testsuite/src/PathTest.cpp | 15 +++++++++++++++ Foundation/testsuite/src/PathTest.h | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Foundation/src/Path.cpp b/Foundation/src/Path.cpp index 059b2b980..eeddd3ad6 100644 --- a/Foundation/src/Path.cpp +++ b/Foundation/src/Path.cpp @@ -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; diff --git a/Foundation/testsuite/src/PathTest.cpp b/Foundation/testsuite/src/PathTest.cpp index 998d70968..4453a8503 100644 --- a/Foundation/testsuite/src/PathTest.cpp +++ b/Foundation/testsuite/src/PathTest.cpp @@ -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); diff --git a/Foundation/testsuite/src/PathTest.h b/Foundation/testsuite/src/PathTest.h index d7334cdef..38459fe82 100644 --- a/Foundation/testsuite/src/PathTest.h +++ b/Foundation/testsuite/src/PathTest.h @@ -34,6 +34,7 @@ public: void testParseWindows2(); void testParseWindows3(); void testParseWindows4(); + void testParseWindows5(); void testParseVMS1(); void testParseVMS2(); void testParseVMS3();