We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e2f8b51 commit 196851cCopy full SHA for 196851c
src/libstd/os.rs
@@ -675,6 +675,11 @@ pub fn mkdir_recursive(p: &Path, mode: c_int) -> bool {
675
/// Lists the contents of a directory
676
#[allow(non_implicitly_copyable_typarams)]
677
pub fn list_dir(p: &Path) -> ~[~str] {
678
+ if p.components.is_empty() {
679
+ // Not sure what the right behavior is here, but this
680
+ // prevents a bounds check failure later
681
+ return ~[];
682
+ }
683
unsafe {
684
#[cfg(target_os = "linux")]
685
#[cfg(target_os = "android")]
@@ -1596,6 +1601,12 @@ mod tests {
1596
1601
}
1597
1602
1598
1603
1604
+ #[test]
1605
+ fn list_dir_empty_path() {
1606
+ let dirs = os::list_dir(&Path(""));
1607
+ assert!(dirs.is_empty());
1608
1609
+
1599
1610
#[test]
1600
1611
fn path_is_dir() {
1612
assert!((os::path_is_dir(&Path("."))));
0 commit comments