Closed
Description
The documentation states:
The final component of the path, if it is a normal file.
If the path terminates in ., .., or consists solely of a root of prefix, file_name will return None.
but:
fn do_file_name(x: &str) {
println!("file_name({}) = {:?}", x, std::path::Path::new(x).file_name());
}
fn main() {
use std::path::Path;
do_file_name("/path/with/dot/.");
do_file_name("/path/with/with/dot/slash/./");
do_file_name("/path/with/dot/double/slash/.//");
do_file_name("/path/with/double/dot/..");
do_file_name("/path/with/nul/bytes/test\0invalid");
}
prints
file_name(/path/with/dot/.) = Some("dot")
file_name(/path/with/with/dot/slash/./) = Some("slash")
file_name(/path/with/dot/double/slash/.//) = Some("slash")
file_name(/path/with/double/dot/..) = None
file_name(/path/with/nul/bytes/testinvalid) = Some("test\u{0}invalid")
(Playground: https://play.rust-lang.org/?gist=2eddf89b4c80926240b9cbd4d6d40821&version=stable&backtrace=0)
I think the documentation for the "ends with ." case is wrong.
Metadata
Metadata
Assignees
Labels
No labels