C#: Handle the places where we could risk that Path.Combine would have thrown away the first argument.

This commit is contained in:
Michael Nebel
2026-06-18 15:29:03 +02:00
parent f7b3f851e8
commit 03b525b689
2 changed files with 7 additions and 2 deletions

View File

@@ -108,7 +108,8 @@ namespace Semmle.Autobuild.Shared
}
var includePath = builder.Actions.PathJoin(include.Value.Split('\\', StringSplitOptions.RemoveEmptyEntries));
ret.Add(new Project<TAutobuildOptions>(builder, builder.Actions.PathJoin(DirectoryName, includePath)));
var path = Path.IsPathRooted(includePath) ? includePath : builder.Actions.PathJoin(DirectoryName, includePath);
ret.Add(new Project<TAutobuildOptions>(builder, path));
}
return ret;
});

View File

@@ -159,7 +159,11 @@ namespace Semmle.Extraction.CSharp
return null;
}
return Path.GetFullPath(Path.Join(projDir?.FullName ?? string.Empty, Path.DirectorySeparatorChar == '/' ? file.Replace("\\", "/") : file));
var normalized = Path.DirectorySeparatorChar == '/' ? file.Replace("\\", "/") : file;
var path = projDir is not null && !Path.IsPathRooted(normalized)
? Path.Join(projDir.FullName, normalized)
: normalized;
return Path.GetFullPath(path);
}
private readonly string[] references;