Fixed #1919 (option '--suppressions file' can not work when filename includes colon)

This commit is contained in:
Daniel Marjamäki 2010-08-03 17:52:03 +02:00
parent 9edecd4a3f
commit 08e2d91372
2 changed files with 39 additions and 2 deletions

View File

@ -68,9 +68,35 @@ std::string Settings::Suppressions::parseFile(std::istream &istr)
unsigned int lineNumber = 0; unsigned int lineNumber = 0;
if (std::getline(lineStream, id, ':')) if (std::getline(lineStream, id, ':'))
{ {
if (std::getline(lineStream, file, ':')) if (std::getline(lineStream, file))
{ {
lineStream >> lineNumber; // If there is not a dot after the last colon in "file" then
// the colon is a separator and the contents after the colon
// is a line number..
// Get position of last colon
const std::string::size_type pos = file.rfind(":");
// if a colon is found and there is no dot after it..
if (pos != std::string::npos &&
file.find(".", pos) == std::string::npos)
{
// Try to parse out the line number
try
{
std::istringstream istr1(file.substr(pos+1));
istr1 >> lineNumber;
}
catch (...)
{
lineNumber = 0;
}
if (lineNumber > 0)
{
file.erase(pos);
}
}
} }
} }

View File

@ -35,6 +35,7 @@ private:
{ {
TEST_CASE(suppressionsBadId1); TEST_CASE(suppressionsBadId1);
TEST_CASE(suppressionsDosFormat); // Ticket #1836 TEST_CASE(suppressionsDosFormat); // Ticket #1836
TEST_CASE(suppressionsFileNameWithColon); // Ticket #1919 - filename includes colon
} }
void suppressionsBadId1() void suppressionsBadId1()
@ -52,6 +53,16 @@ private:
ASSERT_EQUALS(true, suppressions.isSuppressed("abc", "test.cpp", 1)); ASSERT_EQUALS(true, suppressions.isSuppressed("abc", "test.cpp", 1));
ASSERT_EQUALS(true, suppressions.isSuppressed("def", "test.cpp", 1)); ASSERT_EQUALS(true, suppressions.isSuppressed("def", "test.cpp", 1));
} }
void suppressionsFileNameWithColon()
{
Settings::Suppressions suppressions;
std::istringstream s("errorid:c:\\foo.cpp\nerrorid:c:\\bar.cpp:12");
ASSERT_EQUALS("", suppressions.parseFile(s));
ASSERT_EQUALS(true, suppressions.isSuppressed("errorid", "c:\\foo.cpp", 1111));
ASSERT_EQUALS(false, suppressions.isSuppressed("errorid", "c:\\bar.cpp", 10));
ASSERT_EQUALS(true, suppressions.isSuppressed("errorid", "c:\\bar.cpp", 12));
}
}; };
REGISTER_TEST(TestSettings) REGISTER_TEST(TestSettings)