Skip to content
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

fix. Handle missing trailing slash for the Windows drive path. #1031

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

albertleigh
Copy link

@albertleigh albertleigh commented Mar 6, 2025

Handle missing trailing slash for Windows drive paths.

Added a special case to re-append a trailing backslash (\) for Windows drive paths like C: to ensure correct absolute path handling. A new test verifies this behavior by validating path consistency after transformations.

And I added a test case trying to explain everything:

#[test]
#[cfg(feature = "std")]
#[cfg(windows)]
fn extend_empty_segment_to_win_driver() {
    let path_str = r"C:\";
    let prefix_path = PathBuf::from(r"C:\");
    let prefix_path = std::fs::canonicalize(prefix_path).expect("Failed to canonicalize path");
    let mut url = Url::from_file_path(prefix_path).expect("Failed to parse path");
    let empty_segment: [&str; 0] = [];

    url.path_segments_mut()
        .expect("url path")
        .pop_if_empty()
        .extend(empty_segment);

    let path = url
        .to_file_path()
        .expect("Failed to parse the windows driver path");
    assert_eq!(path.to_str(), Some(path_str));
}

Not sure I got it fixed at a right place, please kindly help review. Thanks 😁

@albertleigh albertleigh changed the title fix. Handle missing trailing slash for Windows drive paths. fix. Handle missing trailing slash for Windows drive path. Mar 6, 2025
@albertleigh albertleigh changed the title fix. Handle missing trailing slash for Windows drive path. fix. Handle missing trailing slash for the Windows drive path. Mar 6, 2025
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.

1 participant