@@ -1156,6 +1156,20 @@ impl FusedIterator for Ancestors<'_> {}
1156
1156
/// ```
1157
1157
///
1158
1158
/// Which method works best depends on what kind of situation you're in.
1159
+ ///
1160
+ /// Note that `PathBuf`` does not sanitize arguments, and will build
1161
+ /// paths from strings which include separators, for example:
1162
+ ///
1163
+ /// use std::path::PathBuf;
1164
+ ///
1165
+ /// let mut path = PathBuf::new();
1166
+ ///
1167
+ /// path.push(r"C:\");
1168
+ /// path.push("windows");
1169
+ /// path.push(r"..\otherdir");
1170
+ /// path.push("system32");
1171
+ ///
1172
+ /// path.set_extension(r"\..\temp");
1159
1173
#[ cfg_attr( not( test) , rustc_diagnostic_item = "PathBuf" ) ]
1160
1174
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1161
1175
pub struct PathBuf {
@@ -1379,6 +1393,8 @@ impl PathBuf {
1379
1393
/// `file_name`. The new path will be a sibling of the original path.
1380
1394
/// (That is, it will have the same parent.)
1381
1395
///
1396
+ /// The argument is not sanitized, so can include separators.
1397
+ ///
1382
1398
/// [`self.file_name`]: Path::file_name
1383
1399
/// [`pop`]: PathBuf::pop
1384
1400
///
@@ -1399,6 +1415,12 @@ impl PathBuf {
1399
1415
///
1400
1416
/// buf.set_file_name("baz");
1401
1417
/// assert!(buf == PathBuf::from("/baz"));
1418
+ ///
1419
+ /// buf.set_file_name("../b/c.txt");
1420
+ /// assert!(buf == PathBuf::from("/../b/c.txt"));
1421
+ ///
1422
+ /// buf.set_file_name("baz");
1423
+ /// assert!(buf == PathBuf::from("/../b/baz"));
1402
1424
/// ```
1403
1425
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1404
1426
pub fn set_file_name < S : AsRef < OsStr > > ( & mut self , file_name : S ) {
@@ -1434,6 +1456,8 @@ impl PathBuf {
1434
1456
/// If the file stem contains internal dots and `extension` is empty, part
1435
1457
/// of the old file stem will be considered the new [`self.extension`].
1436
1458
///
1459
+ /// The new `extension` is not sanitized, so may include separators.
1460
+ ///
1437
1461
/// See the examples below.
1438
1462
///
1439
1463
/// [`self.file_name`]: Path::file_name
@@ -1463,6 +1487,9 @@ impl PathBuf {
1463
1487
///
1464
1488
/// p.set_extension("");
1465
1489
/// assert_eq!(Path::new("/feel/the"), p.as_path());
1490
+ ///
1491
+ /// p.set_extension("/darkest.cookie");
1492
+ /// assert_eq!(Path::new("/feel/the./darkest.cookie"), p.as_path());
1466
1493
/// ```
1467
1494
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1468
1495
pub fn set_extension < S : AsRef < OsStr > > ( & mut self , extension : S ) -> bool {
0 commit comments