Skip to content

Commit 46d35f8

Browse files
committed
Fix failing test
1 parent e77671d commit 46d35f8

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/lib.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
html_root_url = "http://doc.rust-lang.org/glob/")]
2626
#![cfg_attr(test, feature(io))]
2727
#![cfg_attr(all(test, windows), feature(std_misc))]
28-
#![feature(path_components_peek, unmarked_api)]
2928

3029
use std::ascii::AsciiExt;
3130
use std::cell::Cell;
@@ -154,15 +153,18 @@ pub fn glob_with(pattern: &str, options: &MatchOptions)
154153
#[cfg(not(windows))]
155154
fn to_scope(p: &Path) -> PathBuf { p.to_path_buf() }
156155

157-
let mut components = Path::new(pattern).components();
156+
let mut components = Path::new(pattern).components().peekable();
158157
loop {
159158
match components.peek() {
160-
Some(Component::Prefix(..)) |
161-
Some(Component::RootDir) => { components.next(); }
159+
Some(&Component::Prefix(..)) |
160+
Some(&Component::RootDir) => { components.next(); }
162161
_ => break,
163162
}
164163
}
165-
let root_len = pattern.len() - components.as_path().to_str().unwrap().len();
164+
let rest = components.map(|s| s.as_os_str()).collect::<PathBuf>();
165+
let normalized_pattern = Path::new(pattern).iter().collect::<PathBuf>();
166+
let root_len = normalized_pattern.to_str().unwrap().len() -
167+
rest.to_str().unwrap().len();
166168
let root = if root_len > 0 {Some(Path::new(&pattern[..root_len]))}
167169
else {None};
168170

@@ -190,6 +192,14 @@ pub fn glob_with(pattern: &str, options: &MatchOptions)
190192
dir_patterns.push(compiled);
191193
}
192194

195+
if root_len == pattern.len() {
196+
dir_patterns.push(Pattern {
197+
original: "".to_string(),
198+
tokens: Vec::new(),
199+
is_recursive: false,
200+
});
201+
}
202+
193203
let require_dir = pattern.chars().next_back().map(path::is_separator) == Some(true);
194204
let todo = Vec::new();
195205

0 commit comments

Comments
 (0)