Skip to content

Commit de0092c

Browse files
committed
No longer treat \ as a path separator on posix systems.
1 parent 85b5513 commit de0092c

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/libstd/path.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ impl GenericPath for PosixPath {
587587
}
588588

589589
fn with_filename(&self, f: &str) -> PosixPath {
590-
assert!(! f.iter().all(windows::is_sep));
590+
assert!(!f.iter().all(posix::is_sep));
591591
self.dir_path().push(f)
592592
}
593593

@@ -648,7 +648,7 @@ impl GenericPath for PosixPath {
648648
fn push_many<S: Str>(&self, cs: &[S]) -> PosixPath {
649649
let mut v = self.components.clone();
650650
for cs.iter().advance |e| {
651-
for e.as_slice().split_iter(windows::is_sep).advance |s| {
651+
for e.as_slice().split_iter(posix::is_sep).advance |s| {
652652
if !s.is_empty() {
653653
v.push(s.to_owned())
654654
}
@@ -662,7 +662,7 @@ impl GenericPath for PosixPath {
662662

663663
fn push(&self, s: &str) -> PosixPath {
664664
let mut v = self.components.clone();
665-
for s.split_iter(windows::is_sep).advance |s| {
665+
for s.split_iter(posix::is_sep).advance |s| {
666666
if !s.is_empty() {
667667
v.push(s.to_owned())
668668
}
@@ -1001,7 +1001,17 @@ pub fn normalize(components: &[~str]) -> ~[~str] {
10011001
cs
10021002
}
10031003

1004-
// Various windows helpers, and tests for the impl.
1004+
// Various posix helpers.
1005+
pub mod posix {
1006+
1007+
#[inline]
1008+
pub fn is_sep(u: char) -> bool {
1009+
u == '/'
1010+
}
1011+
1012+
}
1013+
1014+
// Various windows helpers.
10051015
pub mod windows {
10061016
use libc;
10071017
use option::{None, Option, Some};
@@ -1139,6 +1149,14 @@ mod tests {
11391149

11401150
}
11411151

1152+
#[test]
1153+
fn test_posix_push_with_backslash() {
1154+
let a = PosixPath("/aaa/bbb");
1155+
let b = a.push("x\\y"); // \ is not a file separator for posix paths
1156+
assert_eq!(a.components.len(), 2);
1157+
assert_eq!(b.components.len(), 3);
1158+
}
1159+
11421160
#[test]
11431161
fn test_normalize() {
11441162
fn t(wp: &PosixPath, s: &str) {

0 commit comments

Comments
 (0)