Skip to content

Commit

Permalink
CmdLineParser: ignored paths from projects were not normalized
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Feb 23, 2025
1 parent 2d369e4 commit 6e85f40
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,6 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
}

if (!path.empty()) {
path = Path::removeQuotationMarks(std::move(path));
path = Path::simplifyPath(std::move(path));
mIgnoredPaths.emplace_back(std::move(path));
}
}
Expand Down Expand Up @@ -1589,6 +1587,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a

for (auto& path : mIgnoredPaths)
{
path = Path::removeQuotationMarks(std::move(path));
path = Path::simplifyPath(std::move(path));

bool isdir = false;
if (!Path::exists(path, &isdir) && mSettings.debugignore)
std::cout << "path to ignore does not exist: " << path << std::endl;
Expand Down
12 changes: 12 additions & 0 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ class TestCmdlineParser : public TestFixture {
TEST_CASE(ignorefilepaths6);
TEST_CASE(ignorefilepaths7);
TEST_CASE(ignorefilepaths8);
TEST_CASE(ignorefilepaths9);

TEST_CASE(nonexistentpath);

Expand Down Expand Up @@ -3114,6 +3115,17 @@ class TestCmdlineParser : public TestFixture {
ASSERT_EQUALS("cppcheck: error: could not find or open any of the paths given.\ncppcheck: Maybe all paths were ignored?\n", logger->str());
}

void ignorefilepaths9() {
REDIRECT;
const char * const argv[] = {"cppcheck", "-isrc\\", "src\\file.cpp"};
ASSERT(!fillSettingsFromArgs(argv));
ASSERT_EQUALS(1, parser->getIgnoredPaths().size());
ASSERT_EQUALS("src/", parser->getIgnoredPaths()[0]);
ASSERT_EQUALS(1, parser->getPathNames().size());
ASSERT_EQUALS("src/file.cpp", parser->getPathNames()[0]);
ASSERT_EQUALS("cppcheck: error: could not find or open any of the paths given.\ncppcheck: Maybe all paths were ignored?\n", logger->str());
}

void nonexistentpath() {
REDIRECT;
const char * const argv[] = {"cppcheck", "file.cpp"};
Expand Down

0 comments on commit 6e85f40

Please sign in to comment.