mirror of
https://github.com/pocoproject/poco.git
synced 2025-06-30 16:03:27 +02:00
fix #4005 Poco::Path::getExtension() returns name of the hidden file if no extension is present (#4011)
This commit is contained in:
parent
c7ac8574f8
commit
75b378e540
@ -537,7 +537,7 @@ Path& Path::setBaseName(const std::string& name)
|
|||||||
std::string Path::getBaseName() const
|
std::string Path::getBaseName() const
|
||||||
{
|
{
|
||||||
std::string::size_type pos = _name.rfind('.');
|
std::string::size_type pos = _name.rfind('.');
|
||||||
if (pos != std::string::npos)
|
if (pos != std::string::npos && pos != 0)
|
||||||
return _name.substr(0, pos);
|
return _name.substr(0, pos);
|
||||||
else
|
else
|
||||||
return _name;
|
return _name;
|
||||||
@ -559,7 +559,7 @@ Path& Path::setExtension(const std::string& extension)
|
|||||||
std::string Path::getExtension() const
|
std::string Path::getExtension() const
|
||||||
{
|
{
|
||||||
std::string::size_type pos = _name.rfind('.');
|
std::string::size_type pos = _name.rfind('.');
|
||||||
if (pos != std::string::npos)
|
if (pos != std::string::npos && pos != 0)
|
||||||
return _name.substr(pos + 1);
|
return _name.substr(pos + 1);
|
||||||
else
|
else
|
||||||
return std::string();
|
return std::string();
|
||||||
|
@ -605,6 +605,20 @@ void FileTest::testLongPath()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileTest::testUnixFileExtension()
|
||||||
|
{
|
||||||
|
std::string filePath1 = "/a/b/c/.notextension";
|
||||||
|
Poco::Path path1(filePath1, Poco::Path::Style::PATH_UNIX);
|
||||||
|
|
||||||
|
assertEqual(".notextension", path1.getBaseName());
|
||||||
|
assertEqual("", path1.getExtension());
|
||||||
|
|
||||||
|
std::string filePath2 = "/a/b/c/emptyextension.";
|
||||||
|
Poco::Path path2(filePath2, Poco::Path::Style::PATH_UNIX);
|
||||||
|
|
||||||
|
assertEqual("emptyextension", path2.getBaseName());
|
||||||
|
assertEqual("", path2.getExtension());
|
||||||
|
}
|
||||||
|
|
||||||
void FileTest::setUp()
|
void FileTest::setUp()
|
||||||
{
|
{
|
||||||
@ -654,6 +668,7 @@ CppUnit::Test* FileTest::suite()
|
|||||||
CppUnit_addTest(pSuite, FileTest, testRenameFailIfExists);
|
CppUnit_addTest(pSuite, FileTest, testRenameFailIfExists);
|
||||||
CppUnit_addTest(pSuite, FileTest, testRootDir);
|
CppUnit_addTest(pSuite, FileTest, testRootDir);
|
||||||
CppUnit_addTest(pSuite, FileTest, testLongPath);
|
CppUnit_addTest(pSuite, FileTest, testLongPath);
|
||||||
|
CppUnit_addTest(pSuite, FileTest, testUnixFileExtension);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ public:
|
|||||||
void testRenameFailIfExists();
|
void testRenameFailIfExists();
|
||||||
void testRootDir();
|
void testRootDir();
|
||||||
void testLongPath();
|
void testLongPath();
|
||||||
|
void testUnixFileExtension();
|
||||||
|
|
||||||
void setUp();
|
void setUp();
|
||||||
void tearDown();
|
void tearDown();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user