Skip to content

Conversation

@karthiknadig
Copy link
Member

Fixes #278

@karthiknadig karthiknadig marked this pull request as ready for review January 16, 2026 01:59
@karthiknadig karthiknadig requested a review from Copilot January 16, 2026 01:59
@karthiknadig karthiknadig self-assigned this Jan 16, 2026
@vs-code-engineering vs-code-engineering bot added this to the January 2026 milestone Jan 16, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new utility function strip_trailing_separator() to handle trailing path separators from paths while preserving root paths, addressing issue #278. The function provides a lightweight alternative to norm_case() when only trailing separator removal is needed without full path normalization.

Changes:

  • Added strip_trailing_separator() function with platform-specific implementations for Windows and Unix
  • Enhanced documentation for norm_case(), resolve_symlink(), and expand_path() with detailed usage notes and cross-references
  • Added comprehensive test coverage for the new function on both Unix and Windows platforms
Comments suppressed due to low confidence (2)

crates/pet-fs/src/path.rs:37

  • The hardcoded length check > 3 is a magic number that isn't clearly explained. Consider adding a comment explaining this preserves Windows root paths like C:\ (3 characters) or using a named constant. Additionally, this doesn't account for edge cases like C:/ (forward slashes on Windows) which would have length 3 but should also be preserved.
        while result.len() > 3 && (result.ends_with('\\') || result.ends_with('/')) {
            result.pop();
        }

crates/pet-fs/src/path.rs:354

  • The Windows tests are missing coverage for important edge cases: UNC paths (\\?\C:\path\), network paths (\\server\share\), paths with forward slashes that equal length 3 (C:/), and paths with mixed trailing separators (C:\path\/). These edge cases should be tested given the complexity of Windows path handling.
        assert_eq!(strip_trailing_separator("C:\\"), PathBuf::from("C:\\"));

Comment on lines +33 to +35
// On Windows, preserve root paths like "C:\"
let mut result = path_str.to_string();
while result.len() > 3 && (result.ends_with('\\') || result.ends_with('/')) {
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Windows implementation has a logic error. It preserves paths longer than 3 characters (e.g., C:\) but will fail for UNC paths like \\server\share\ (length > 3) and network paths like \\server\ which should be preserved as root paths. The check should be more sophisticated to handle UNC/network paths (\\?\..., \\server\...) similar to how normalize_case_windows() uses Path::parent() for robust root detection.

This issue also appears in the following locations of the same file:

  • line 35
  • line 354
Suggested change
// On Windows, preserve root paths like "C:\"
let mut result = path_str.to_string();
while result.len() > 3 && (result.ends_with('\\') || result.ends_with('/')) {
// On Windows, preserve root paths (e.g. "C:\", "\\server\", "\\?\C:\")
let mut result = path_str.to_string();
while (result.ends_with('\\') || result.ends_with('/'))
&& Path::new(&result).parent().is_some()
{

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audit norm_case usage and consider separating path normalization responsibilities

3 participants