@@ -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.
910pub 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