Skip to content

strip_trailing_separator incorrectly handles UNC and network paths on Windows #294

@karthiknadig

Description

@karthiknadig

Description

The strip_trailing_separator function in crates/pet-fs/src/path.rs has a logic error on Windows. The current implementation uses result.len() > 3 to preserve root paths like C:\, but this fails for:

  1. UNC paths like \\server\share\ (length > 3) which would incorrectly have the trailing separator stripped
  2. Network paths like \\server\ which should be preserved as root paths
  3. Extended-length paths like \\?\C:\ which should also be preserved

Current Code (Line 35)

while result.len() > 3 && (result.ends_with('\\') || result.ends_with('/')) {
    result.pop();
}

Proposed Fix

Use Path::parent().is_some() for robust root detection, similar to how normalize_case_windows() already handles this correctly:

while (result.ends_with('\\') || result.ends_with('/'))
    && Path::new(&result).parent().is_some()
{
    result.pop();
}

Origin

This issue was identified in the review of PR #279.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue identified by VS Code Team member as probable bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions