Skip to content

Commit

Permalink
Shared: Add trailing slash to driver letter TRAP IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
hvitved committed Feb 13, 2025
1 parent 6273e8d commit d14cbf8
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions shared/tree-sitter-extractor/src/file_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ pub fn normalize_path(path: &Path) -> String {
// have to do a bit of work removing certain prefixes and replacing
// backslashes.
let mut components: Vec<String> = Vec::new();
let mut is_disk = false;
for component in path.components() {
match component {
std::path::Component::Prefix(prefix) => match prefix.kind() {
std::path::Prefix::Disk(letter) | std::path::Prefix::VerbatimDisk(letter) => {
is_disk = true;
components.push(format!("{}:", letter as char));
}
std::path::Prefix::Verbatim(x) | std::path::Prefix::DeviceNS(x) => {
Expand All @@ -31,6 +33,11 @@ pub fn normalize_path(path: &Path) -> String {
std::path::Component::ParentDir => {}
}
}
if components.len() == 1 && is_disk {
// If the path is just a drive letter, we need to add a trailing
// slash to match the CodeQL spec.
components.push("".to_string());
}
components.join("/")
} else {
// For other operating systems, we can use the canonicalized path
Expand Down

0 comments on commit d14cbf8

Please sign in to comment.