Skip to content

PathBuf::set_extension accepts an extension containing slashes #32497

Closed
@oconnor663

Description

@oconnor663

The following code runs without any errors:

let mut p = Path::new("myfile.pdf").to_owned();
p.set_extension("txt/doc");
println!("{:?} {}", p, p.components().count());
// "myfile.txt/doc" 2

I'm not sure what I expected this to do. Maybe panic? I would also have been ok with short-circuiting and returning false. But succeeding feels weird to me.

The set_file_name method has a similar problem. There's no return value on that one, so panicking might be the only option, if we don't like allowing slashes in the new filename.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`C-bugCategory: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions