about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-07-31 00:22:21 -0700
committerbors <bors@rust-lang.org>2013-07-31 00:22:21 -0700
commit8a737b502067b1896686bd1f9df7a1446296d80b (patch)
tree2aee9c637f58b8b18953ab31b3fb31156b1035c5
parent4fbd37d4bdabb60e20b6dada36ff23c96e90e482 (diff)
parentde0092c48ec11a1da78bcb267fa057cf9519e683 (diff)
downloadrust-8a737b502067b1896686bd1f9df7a1446296d80b.tar.gz
rust-8a737b502067b1896686bd1f9df7a1446296d80b.zip
auto merge of #8138 : Dretch/rust/posix-path-push, r=pcwalton
\ is allowed inside file names on linux, for example my system has a file at:

`/run/udev/firmware-missing/intel-ucode\x2f06-3a-09`
-rw-r--r--src/libstd/path.rs26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index ef7a055b0e7..af6bfc16e54 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -587,7 +587,7 @@ impl GenericPath for PosixPath {
     }
 
     fn with_filename(&self, f: &str) -> PosixPath {
-        assert!(! f.iter().all(windows::is_sep));
+        assert!(!f.iter().all(posix::is_sep));
         self.dir_path().push(f)
     }
 
@@ -648,7 +648,7 @@ impl GenericPath for PosixPath {
     fn push_many<S: Str>(&self, cs: &[S]) -> PosixPath {
         let mut v = self.components.clone();
         for cs.iter().advance |e| {
-            for e.as_slice().split_iter(windows::is_sep).advance |s| {
+            for e.as_slice().split_iter(posix::is_sep).advance |s| {
                 if !s.is_empty() {
                     v.push(s.to_owned())
                 }
@@ -662,7 +662,7 @@ impl GenericPath for PosixPath {
 
     fn push(&self, s: &str) -> PosixPath {
         let mut v = self.components.clone();
-        for s.split_iter(windows::is_sep).advance |s| {
+        for s.split_iter(posix::is_sep).advance |s| {
             if !s.is_empty() {
                 v.push(s.to_owned())
             }
@@ -1001,7 +1001,17 @@ pub fn normalize(components: &[~str]) -> ~[~str] {
     cs
 }
 
-// Various windows helpers, and tests for the impl.
+// Various posix helpers.
+pub mod posix {
+
+    #[inline]
+    pub fn is_sep(u: char) -> bool {
+        u == '/'
+    }
+
+}
+
+// Various windows helpers.
 pub mod windows {
     use libc;
     use option::{None, Option, Some};
@@ -1140,6 +1150,14 @@ mod tests {
     }
 
     #[test]
+    fn test_posix_push_with_backslash() {
+        let a = PosixPath("/aaa/bbb");
+        let b = a.push("x\\y"); // \ is not a file separator for posix paths
+        assert_eq!(a.components.len(), 2);
+        assert_eq!(b.components.len(), 3);
+    }
+
+    #[test]
     fn test_normalize() {
         fn t(wp: &PosixPath, s: &str) {
             let ss = wp.to_str();