Skip to content

Commit c77c5c4

Browse files
committed
Added is_restricted() to path
1 parent b07eab5 commit c77c5c4

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/libcore/path.rs

+26
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub trait GenericPath {
6565
pure fn pop() -> Self;
6666

6767
pure fn unsafe_join((&Self)) -> Self;
68+
pure fn is_restricted() -> bool;
6869

6970
pure fn normalize() -> Self;
7071
}
@@ -496,6 +497,10 @@ impl GenericPath for PosixPath {
496497
}
497498
}
498499

500+
pure fn is_restricted() -> bool {
501+
false
502+
}
503+
499504
pure fn push_many(cs: &[~str]) -> PosixPath {
500505
let mut v = copy self.components;
501506
for cs.each |e| {
@@ -738,6 +743,19 @@ impl GenericPath for WindowsPath {
738743
}
739744
}
740745

746+
pure fn is_restricted() -> bool {
747+
match self.filestem() {
748+
Some(stem) => {
749+
match stem.to_lower() {
750+
~"con" | ~"aux" | ~"com1" | ~"com2" | ~"com3" | ~"com4" |
751+
~"lpt1" | ~"lpt2" | ~"lpt3" | ~"prn" | ~"nul" => true,
752+
_ => false
753+
}
754+
},
755+
None => false
756+
}
757+
}
758+
741759
pure fn push_many(cs: &[~str]) -> WindowsPath {
742760
let mut v = copy self.components;
743761
for cs.each |e| {
@@ -1094,4 +1112,12 @@ mod tests {
10941112
.normalize()),
10951113
"C:\\foo");
10961114
}
1115+
1116+
#[test]
1117+
fn test_windows_path_restrictions() {
1118+
assert WindowsPath("hi").is_restricted() == false;
1119+
assert WindowsPath("C:\\NUL").is_restricted() == true;
1120+
assert WindowsPath("C:\\COM1.TXT").is_restricted() == true;
1121+
assert WindowsPath("c:\\prn.exe").is_restricted() == true;
1122+
}
10971123
}

0 commit comments

Comments
 (0)