mirror of
https://github.com/github/codeql.git
synced 2025-12-16 08:43:11 +01:00
Merge pull request #18770 from hvitved/shared/windows-drive-letter-trap-id
Rust extractors: Normalize drive letter paths with a trailing `/`
This commit is contained in:
@@ -8,7 +8,8 @@ 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();
|
||||
for component in path.components() {
|
||||
let mut path_components = path.components().peekable();
|
||||
while let Some(component) = path_components.next() {
|
||||
match component {
|
||||
std::path::Component::Prefix(prefix) => match prefix.kind() {
|
||||
std::path::Prefix::Disk(letter) | std::path::Prefix::VerbatimDisk(letter) => {
|
||||
@@ -26,7 +27,13 @@ pub fn normalize_path(path: &Path) -> String {
|
||||
std::path::Component::Normal(n) => {
|
||||
components.push(n.to_string_lossy().to_string());
|
||||
}
|
||||
std::path::Component::RootDir => {}
|
||||
std::path::Component::RootDir => {
|
||||
if path_components.peek().is_none() {
|
||||
// The path points at a root directory, so we need to add a
|
||||
// trailing slash, e.g. `C:/` instead of `C:`.
|
||||
components.push("".to_string());
|
||||
}
|
||||
}
|
||||
std::path::Component::CurDir => {}
|
||||
std::path::Component::ParentDir => {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user