From 08e2d9137228e31e42212fbc241b49b19fd028e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 3 Aug 2010 17:52:03 +0200 Subject: [PATCH] Fixed #1919 (option '--suppressions file' can not work when filename includes colon) --- lib/settings.cpp | 30 ++++++++++++++++++++++++++++-- test/testsettings.cpp | 11 +++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/settings.cpp b/lib/settings.cpp index 555e6cf7e..314bbb53d 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -68,9 +68,35 @@ std::string Settings::Suppressions::parseFile(std::istream &istr) unsigned int lineNumber = 0; 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); + } + } } } diff --git a/test/testsettings.cpp b/test/testsettings.cpp index 4e3499d3a..b09e1dced 100644 --- a/test/testsettings.cpp +++ b/test/testsettings.cpp @@ -35,6 +35,7 @@ private: { TEST_CASE(suppressionsBadId1); TEST_CASE(suppressionsDosFormat); // Ticket #1836 + TEST_CASE(suppressionsFileNameWithColon); // Ticket #1919 - filename includes colon } void suppressionsBadId1() @@ -52,6 +53,16 @@ private: ASSERT_EQUALS(true, suppressions.isSuppressed("abc", "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)