Added is_restricted() to path
This commit is contained in:
parent
b07eab5faa
commit
c77c5c4674
1 changed files with 26 additions and 0 deletions
|
@ -65,6 +65,7 @@ pub trait GenericPath {
|
|||
pure fn pop() -> Self;
|
||||
|
||||
pure fn unsafe_join((&Self)) -> Self;
|
||||
pure fn is_restricted() -> bool;
|
||||
|
||||
pure fn normalize() -> Self;
|
||||
}
|
||||
|
@ -496,6 +497,10 @@ impl GenericPath for PosixPath {
|
|||
}
|
||||
}
|
||||
|
||||
pure fn is_restricted() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
pure fn push_many(cs: &[~str]) -> PosixPath {
|
||||
let mut v = copy self.components;
|
||||
for cs.each |e| {
|
||||
|
@ -738,6 +743,19 @@ impl GenericPath for WindowsPath {
|
|||
}
|
||||
}
|
||||
|
||||
pure fn is_restricted() -> bool {
|
||||
match self.filestem() {
|
||||
Some(stem) => {
|
||||
match stem.to_lower() {
|
||||
~"con" | ~"aux" | ~"com1" | ~"com2" | ~"com3" | ~"com4" |
|
||||
~"lpt1" | ~"lpt2" | ~"lpt3" | ~"prn" | ~"nul" => true,
|
||||
_ => false
|
||||
}
|
||||
},
|
||||
None => false
|
||||
}
|
||||
}
|
||||
|
||||
pure fn push_many(cs: &[~str]) -> WindowsPath {
|
||||
let mut v = copy self.components;
|
||||
for cs.each |e| {
|
||||
|
@ -1094,4 +1112,12 @@ mod tests {
|
|||
.normalize()),
|
||||
"C:\\foo");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_windows_path_restrictions() {
|
||||
assert WindowsPath("hi").is_restricted() == false;
|
||||
assert WindowsPath("C:\\NUL").is_restricted() == true;
|
||||
assert WindowsPath("C:\\COM1.TXT").is_restricted() == true;
|
||||
assert WindowsPath("c:\\prn.exe").is_restricted() == true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue