From e7e41a846578de9c1dc1ccf8ac4bbb0a3a5dea60 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Sat, 8 Aug 2020 18:06:04 +0800 Subject: [PATCH 1/2] Add additonal case for Path starts with Show what happens if there is an extra extension --- library/std/src/path.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 392c815ef28..e8aa9e27c0f 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -2087,9 +2087,12 @@ fn _strip_prefix(&self, base: &Path) -> Result<&Path, StripPrefixError> { /// assert!(path.starts_with("/etc")); /// assert!(path.starts_with("/etc/")); /// assert!(path.starts_with("/etc/passwd")); - /// assert!(path.starts_with("/etc/passwd/")); + /// assert!(path.starts_with("/etc/passwd/")); // extra slash(es) is okay /// /// assert!(!path.starts_with("/e")); + /// assert!(!path.starts_with("/etc/passwd.txt")); + /// + /// assert!(!Path::new("/etc/foo.rs").starts_with("/etc/foo")); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn starts_with>(&self, base: P) -> bool { From 4b549fa043486b10673d69ba547522238bb2f25f Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Mon, 10 Aug 2020 00:43:45 +0800 Subject: [PATCH 2/2] show multiple slashes starts_with Path example Co-authored-by: Joshua Nelson --- library/std/src/path.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/std/src/path.rs b/library/std/src/path.rs index e8aa9e27c0f..e543006e394 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -2087,7 +2087,8 @@ fn _strip_prefix(&self, base: &Path) -> Result<&Path, StripPrefixError> { /// assert!(path.starts_with("/etc")); /// assert!(path.starts_with("/etc/")); /// assert!(path.starts_with("/etc/passwd")); - /// assert!(path.starts_with("/etc/passwd/")); // extra slash(es) is okay + /// assert!(path.starts_with("/etc/passwd/")); // extra slash is okay + /// assert!(path.starts_with("/etc/passwd///")); // multiple extra slashes are okay /// /// assert!(!path.starts_with("/e")); /// assert!(!path.starts_with("/etc/passwd.txt"));