mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +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
|
// have to do a bit of work removing certain prefixes and replacing
|
||||||
// backslashes.
|
// backslashes.
|
||||||
let mut components: Vec<String> = Vec::new();
|
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 {
|
match component {
|
||||||
std::path::Component::Prefix(prefix) => match prefix.kind() {
|
std::path::Component::Prefix(prefix) => match prefix.kind() {
|
||||||
std::path::Prefix::Disk(letter) | std::path::Prefix::VerbatimDisk(letter) => {
|
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) => {
|
std::path::Component::Normal(n) => {
|
||||||
components.push(n.to_string_lossy().to_string());
|
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::CurDir => {}
|
||||||
std::path::Component::ParentDir => {}
|
std::path::Component::ParentDir => {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user