Skip to content

Commit

Permalink
Improve handling of relative file paths in report files
Browse files Browse the repository at this point in the history
- Up to know we were stating in our [Wiki](https://github.com/SonarOpenCommunity/sonar-cxx/wiki/Troubleshooting-Reports): Relative paths in report files are always relative to the project base directory. Start relative paths always with .\ on Windows or ./ on Linux.
- relative paths starting with '..' were resolved to null in the past. "No file" results in adding an issue on project level (project issue). We replace now '..' with '.' (current directory=project base directory). This leads at least to an error message an that and the issue is not added to the project because typically no indexed file exists.
- The real problem is that tools generate reports with relative paths without defining which base directory is referred to. This problem remains and must be solved via the CI/CD and tool configuration.
- close SonarOpenCommunity#2741
  • Loading branch information
guwirth committed Sep 10, 2024
1 parent 95ea2ae commit 3dfe2e1
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ public class CxxReportLocation {

public CxxReportLocation(@Nullable String file, @Nullable String line, @Nullable String column, String info) {
super();
// normalize file, removing double and single dot path steps => avoids duplicates

// Normalize file using separators in UNIX format, removing double and single dot path steps. This is to avoid
// duplicates in zhe issue containers because they are using the file as key. PathUtils.sanitize uses
// FilenameUtils.normalize internally, for relative paths starting with a double dot will cause that path segment
// and the one before to be removed. If the double dot has no parent path segment to work with, null is returned.
// To avoid this we replace '..\' with '.\'.
if (file != null && file.startsWith("..")) {
file = file.substring(1, file.length());
}
this.file = PathUtils.sanitize(file);
this.line = line;
this.column = column;
Expand Down

0 comments on commit 3dfe2e1

Please sign in to comment.