From 9218afbb56ea21fd5bf24b5e8edb59593ae97fc7 Mon Sep 17 00:00:00 2001 From: siren186 <765495939@qq.com> Date: Fri, 12 Sep 2025 10:16:46 +0800 Subject: [PATCH 1/2] fix(Path): Poco::Path::forDirectory("C:") throws if the path is disk-letter only #4573 --- Foundation/src/Path.cpp | 10 ++++++-- Foundation/testsuite/src/PathTest.cpp | 34 +++++++++++++++++++++++++++ Foundation/testsuite/src/PathTest.h | 1 + 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Foundation/src/Path.cpp b/Foundation/src/Path.cpp index 397f50529b..1c527be1fd 100644 --- a/Foundation/src/Path.cpp +++ b/Foundation/src/Path.cpp @@ -821,8 +821,14 @@ void Path::parseWindows(const std::string& path) _absolute = true; _device += d; ++it; - if (it == end || (*it != '\\' && *it != '/')) throw PathSyntaxException(path); - ++it; + if (it != end) + { + if ((*it != '\\' && *it != '/')) + { + throw PathSyntaxException(path); + } + ++it; + } } else --it; } diff --git a/Foundation/testsuite/src/PathTest.cpp b/Foundation/testsuite/src/PathTest.cpp index 5f9c3c6be9..49e7192fc2 100644 --- a/Foundation/testsuite/src/PathTest.cpp +++ b/Foundation/testsuite/src/PathTest.cpp @@ -836,6 +836,39 @@ void PathTest::testParseWindows4() } +void PathTest::testParseWindows5() +{ + Path p; + p.parse("C:", Path::PATH_WINDOWS); + assertTrue(!p.isRelative()); + assertTrue(p.isAbsolute()); + assertTrue(p.depth() == 0); + assertTrue(p.isDirectory()); + assertTrue(p.toString(Path::PATH_WINDOWS) == "C:\\"); + + p.parse("C:\\", Path::PATH_WINDOWS); + assertTrue(!p.isRelative()); + assertTrue(p.isAbsolute()); + assertTrue(p.depth() == 0); + assertTrue(p.isDirectory()); + assertTrue(p.toString(Path::PATH_WINDOWS) == "C:\\"); + + p.parse("\\\\?\\C:", Path::PATH_WINDOWS); + assertTrue(!p.isRelative()); + assertTrue(p.isAbsolute()); + assertTrue(p.depth() == 1); + assertTrue(p.isDirectory()); + assertTrue(p.toString(Path::PATH_WINDOWS) == "\\\\?\\C:\\"); + + p.parse("\\\\?\\C:\\", Path::PATH_WINDOWS); + assertTrue(!p.isRelative()); + assertTrue(p.isAbsolute()); + assertTrue(p.depth() == 1); + assertTrue(p.isDirectory()); + assertTrue(p.toString(Path::PATH_WINDOWS) == "\\\\?\\C:\\"); +} + + void PathTest::testParseVMS1() { Path p; @@ -1697,6 +1730,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 d29336693b..7ecf766828 100644 --- a/Foundation/testsuite/src/PathTest.h +++ b/Foundation/testsuite/src/PathTest.h @@ -33,6 +33,7 @@ class PathTest: public CppUnit::TestCase void testParseWindows2(); void testParseWindows3(); void testParseWindows4(); + void testParseWindows5(); void testParseVMS1(); void testParseVMS2(); void testParseVMS3(); From dece6a624206a058a98f6cd5dee6da4a0d6baae0 Mon Sep 17 00:00:00 2001 From: siren186 <765495939@qq.com> Date: Fri, 12 Sep 2025 11:33:58 +0800 Subject: [PATCH 2/2] keep code style --- Foundation/testsuite/src/PathTest.cpp | 40 +++++++++++++-------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Foundation/testsuite/src/PathTest.cpp b/Foundation/testsuite/src/PathTest.cpp index 49e7192fc2..dabe8f8aa6 100644 --- a/Foundation/testsuite/src/PathTest.cpp +++ b/Foundation/testsuite/src/PathTest.cpp @@ -840,32 +840,32 @@ void PathTest::testParseWindows5() { Path p; p.parse("C:", Path::PATH_WINDOWS); - assertTrue(!p.isRelative()); - assertTrue(p.isAbsolute()); - assertTrue(p.depth() == 0); - assertTrue(p.isDirectory()); - assertTrue(p.toString(Path::PATH_WINDOWS) == "C:\\"); + assertTrue (!p.isRelative()); + assertTrue (p.isAbsolute()); + assertTrue (p.depth() == 0); + assertTrue (p.isDirectory()); + assertTrue (p.toString(Path::PATH_WINDOWS) == "C:\\"); p.parse("C:\\", Path::PATH_WINDOWS); - assertTrue(!p.isRelative()); - assertTrue(p.isAbsolute()); - assertTrue(p.depth() == 0); - assertTrue(p.isDirectory()); - assertTrue(p.toString(Path::PATH_WINDOWS) == "C:\\"); + assertTrue (!p.isRelative()); + assertTrue (p.isAbsolute()); + assertTrue (p.depth() == 0); + assertTrue (p.isDirectory()); + assertTrue (p.toString(Path::PATH_WINDOWS) == "C:\\"); p.parse("\\\\?\\C:", Path::PATH_WINDOWS); - assertTrue(!p.isRelative()); - assertTrue(p.isAbsolute()); - assertTrue(p.depth() == 1); - assertTrue(p.isDirectory()); - assertTrue(p.toString(Path::PATH_WINDOWS) == "\\\\?\\C:\\"); + assertTrue (!p.isRelative()); + assertTrue (p.isAbsolute()); + assertTrue (p.depth() == 1); + assertTrue (p.isDirectory()); + assertTrue (p.toString(Path::PATH_WINDOWS) == "\\\\?\\C:\\"); p.parse("\\\\?\\C:\\", Path::PATH_WINDOWS); - assertTrue(!p.isRelative()); - assertTrue(p.isAbsolute()); - assertTrue(p.depth() == 1); - assertTrue(p.isDirectory()); - assertTrue(p.toString(Path::PATH_WINDOWS) == "\\\\?\\C:\\"); + assertTrue (!p.isRelative()); + assertTrue (p.isAbsolute()); + assertTrue (p.depth() == 1); + assertTrue (p.isDirectory()); + assertTrue (p.toString(Path::PATH_WINDOWS) == "\\\\?\\C:\\"); }