Skip to content

Fix #14983 (GUI: exclude file with relative path) - #8804

Open
danmar wants to merge 1 commit into
cppcheck-opensource:mainfrom
cppchecksolutions:fix-14983
Open

Fix #14983 (GUI: exclude file with relative path)#8804
danmar wants to merge 1 commit into
cppcheck-opensource:mainfrom
cppchecksolutions:fix-14983

Conversation

@danmar

@danmar danmar commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@danmar
danmar requested review from ludviggunne and a lite review from Copilot August 20, 2026 19:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses GUI project-file path handling for excluded paths by centralizing “make path relative to project directory” logic in ProjectFile, reusing it in the dialog, and adding regression tests.

Changes:

  • Introduce ProjectFile::getRelativePath() to convert absolute paths to project-relative paths with a cutoff for paths that traverse too far upward.
  • Update ProjectFileDialog browse helpers to use the centralized relative-path logic.
  • Normalize excluded paths in ProjectFile::setExcludedPaths() and add unit tests covering relative/absolute edge cases.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
gui/test/projectfile/testprojectfile.h Adds new test slot declarations for excluded-path relativization behavior.
gui/test/projectfile/testprojectfile.cpp Adds tests validating when excluded paths are converted to relative vs kept absolute.
gui/projectfiledialog.cpp Uses ProjectFile::getRelativePath() instead of duplicating relative-path conversion logic.
gui/projectfile.h Declares the new getRelativePath() helper with documentation.
gui/projectfile.cpp Implements getRelativePath() and applies it when setting excluded paths.
Suppressed comments (1)

gui/test/projectfile/testprojectfile.cpp:226

  • This comment says "more than 2 parent folders" but the behavior under test keeps the path absolute when the relative form would start with "../.." (i.e. 2 or more levels up). Please update the comment to match the implemented threshold.
// Absolute path is kept as-is when making it relative would require walking up more than 2 parent folders

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread gui/projectfile.h
Comment on lines +450 to +455
/**
* @brief Convert an absolute path to a path relative to this project's directory.
* If the relative path would need to walk up more than 2 parent folders
* (i.e. "../../...") the absolute path is returned unchanged instead.
* @param absolutePath Absolute path to convert.
*/
QCOMPARE(settings.userIncludes.size(), 0);
}

// Absolute path is made relative when it does not require walking up more than 2 parent folders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants