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

PathBuf::set_extension accepts an extension containing slashes #32497

Closed
oconnor663 opened this issue Mar 26, 2016 · 4 comments · Fixed by #125070
Closed

PathBuf::set_extension accepts an extension containing slashes #32497

oconnor663 opened this issue Mar 26, 2016 · 4 comments · Fixed by #125070
Labels
A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@oconnor663
Copy link
Contributor

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.

@oconnor663
Copy link
Contributor Author

@steveklabnik steveklabnik added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed A-libs labels Mar 24, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 24, 2017
@steveklabnik
Copy link
Member

Triage: not aware of any changes.

@ChrisDenton ChrisDenton added the A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` label Jan 26, 2023
@tbu-
Copy link
Contributor

tbu- commented Jan 16, 2025

Fixed in #125070 by panicking if the "extension" contains slashes.

@ChrisDenton
Copy link
Member

Closing as complete for that reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-io Area: `std::io`, `std::fs`, `std::net` and `std::path` C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants