@@ -65,6 +65,7 @@ pub trait GenericPath {
65
65
pure fn pop( ) -> Self ;
66
66
67
67
pure fn unsafe_join( ( & Self ) ) -> Self ;
68
+ pure fn is_restricted( ) -> bool ;
68
69
69
70
pure fn normalize( ) -> Self ;
70
71
}
@@ -496,6 +497,10 @@ impl GenericPath for PosixPath {
496
497
}
497
498
}
498
499
500
+ pure fn is_restricted ( ) -> bool {
501
+ false
502
+ }
503
+
499
504
pure fn push_many ( cs : & [ ~str ] ) -> PosixPath {
500
505
let mut v = copy self . components ;
501
506
for cs. each |e| {
@@ -738,6 +743,19 @@ impl GenericPath for WindowsPath {
738
743
}
739
744
}
740
745
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
+
741
759
pure fn push_many ( cs : & [ ~str ] ) -> WindowsPath {
742
760
let mut v = copy self . components ;
743
761
for cs. each |e| {
@@ -1094,4 +1112,12 @@ mod tests {
1094
1112
. normalize ( ) ) ,
1095
1113
"C:\\ foo" ) ;
1096
1114
}
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
+ }
1097
1123
}
0 commit comments