Skip to content

Commit

Permalink
No longer treat \ as a path separator on posix systems.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dretch committed Jul 30, 2013
1 parent 85b5513 commit de0092c
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/libstd/path.rs
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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())
}
Expand All @@ -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())
}
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -1139,6 +1149,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) {
Expand Down

5 comments on commit de0092c

@bors
Copy link
Contributor

@bors bors commented on de0092c Jul 31, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pcwalton
at Dretch@de0092c

@bors
Copy link
Contributor

@bors bors commented on de0092c Jul 31, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging Dretch/rust/posix-path-push = de0092c into auto

@bors
Copy link
Contributor

@bors bors commented on de0092c Jul 31, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dretch/rust/posix-path-push = de0092c merged ok, testing candidate = 8a737b5

@bors
Copy link
Contributor

@bors bors commented on de0092c Jul 31, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 8a737b5

Please sign in to comment.