Skip to content

Rust extractors: Normalize drive letter paths with a trailing / #18770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions shared/tree-sitter-extractor/src/file_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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 => {}
}
Expand Down
Loading