Skip to content

Commit c3cf7c2

Browse files
redsun82Copilot
andcommitted
Use absolute path fallback instead of file: URI
Drop the `url` crate dependency. When a path can't be relativized against the source root, emit it as a bare absolute path and let the CLI's SARIF generator handle URI conversion downstream. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 57ac019 commit c3cf7c2

3 files changed

Lines changed: 7 additions & 22 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shared/tree-sitter-extractor/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ lazy_static = "1.5.0"
1818
serde = { version = "1.0", features = ["derive"] }
1919
serde_json = "1.0"
2020
chrono = { version = "0.4.42", features = ["serde"] }
21-
url = "2.5"
2221
num_cpus = "1.17.0"
2322
zstd = "0.13.3"
2423
yeast = { path = "../yeast" }

shared/tree-sitter-extractor/src/file_paths.rs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,15 @@ use std::{
44
};
55

66
/// Given an absolute path, returns a relative path if it's under `source_root`,
7-
/// otherwise a properly-encoded `file:` URI. This is used for diagnostic locations, which
7+
/// otherwise the absolute path as-is. This is used for diagnostic locations, which
88
/// should use relative paths per the CodeQL diagnostic message format spec.
9+
/// Absolute path fallback is handled downstream by the CLI's SARIF generator.
910
pub fn relativize_for_diagnostic(path: &Path, source_root: Option<&Path>) -> String {
1011
source_root
1112
.and_then(|root| path.strip_prefix(root).ok())
1213
.and_then(|rel| rel.to_str())
1314
.map(|s| s.to_owned())
14-
.unwrap_or_else(|| path_to_file_uri(path))
15-
}
16-
17-
/// Convert a path to a `file:` URI, using the `url` crate for proper percent-encoding.
18-
/// Falls back to a simple `file://` prefix if the `url` crate can't handle the path.
19-
fn path_to_file_uri(path: &Path) -> String {
20-
url::Url::from_file_path(path)
21-
.map(|u| u.to_string())
22-
.unwrap_or_else(|()| format!("file://{}", path.display()))
15+
.unwrap_or_else(|| path.display().to_string())
2316
}
2417

2518
/// This represents the minimum supported path transformation that is needed to support extracting
@@ -256,23 +249,17 @@ mod tests {
256249
}
257250

258251
#[test]
259-
fn relativize_outside_source_root_produces_file_uri() {
252+
fn relativize_outside_source_root_returns_absolute() {
260253
let path = Path::new("/other/location/foo.rb");
261254
let result = relativize_for_diagnostic(path, Some(Path::new("/home/runner/work/repo")));
262-
assert_eq!(result, "file:///other/location/foo.rb");
255+
assert_eq!(result, "/other/location/foo.rb");
263256
}
264257

265258
#[test]
266-
fn relativize_no_source_root_produces_file_uri() {
259+
fn relativize_no_source_root_returns_absolute() {
267260
let path = Path::new("/home/runner/work/repo/src/foo.rb");
268261
let result = relativize_for_diagnostic(path, None);
269-
assert_eq!(result, "file:///home/runner/work/repo/src/foo.rb");
270-
}
271-
272-
#[test]
273-
fn path_to_file_uri_encodes_spaces() {
274-
let result = path_to_file_uri(Path::new("/home/user/my project/foo.rb"));
275-
assert_eq!(result, "file:///home/user/my%20project/foo.rb");
262+
assert_eq!(result, "/home/runner/work/repo/src/foo.rb");
276263
}
277264

278265
#[test]

0 commit comments

Comments
 (0)