mirror of
https://github.com/github/codeql.git
synced 2026-05-14 03:09:26 +02:00
Fix Windows path handling in diagnostic relativization
Canonicalize `current_dir()` to match canonicalized file paths (avoids `\\?\` prefix mismatch on Windows), and normalize backslashes to forward slashes in relative diagnostic paths. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -94,7 +94,7 @@ pub fn run(options: Options) -> std::io::Result<()> {
|
||||
node_types::read_node_types_str("erb", tree_sitter_embedded_template::NODE_TYPES)?;
|
||||
let lines: std::io::Result<Vec<String>> = std::io::BufReader::new(file_list).lines().collect();
|
||||
let lines = lines?;
|
||||
let source_root = std::env::current_dir().ok();
|
||||
let source_root = std::env::current_dir().ok().and_then(|d| d.canonicalize().ok());
|
||||
lines
|
||||
.par_iter()
|
||||
.try_for_each(|line| {
|
||||
|
||||
@@ -298,7 +298,9 @@ pub fn extract(
|
||||
yeast_runner: Option<&yeast::Runner<'_>>,
|
||||
) {
|
||||
let path_str = file_paths::normalize_and_transform_path(path, transformer);
|
||||
let source_root = std::env::current_dir().ok();
|
||||
let source_root = std::env::current_dir()
|
||||
.ok()
|
||||
.and_then(|d| d.canonicalize().ok());
|
||||
let diagnostics_path = file_paths::relativize_for_diagnostic(path, source_root.as_deref());
|
||||
let span = tracing::span!(
|
||||
tracing::Level::TRACE,
|
||||
|
||||
@@ -11,7 +11,7 @@ pub fn relativize_for_diagnostic(path: &Path, source_root: Option<&Path>) -> Str
|
||||
source_root
|
||||
.and_then(|root| path.strip_prefix(root).ok())
|
||||
.and_then(|rel| rel.to_str())
|
||||
.map(|s| s.to_owned())
|
||||
.map(|s| s.replace('\\', "/"))
|
||||
.unwrap_or_else(|| path.display().to_string())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user