@@ -124,16 +124,25 @@ pub fn component(
124
124
Ok ( input)
125
125
}
126
126
127
- fn check_win_devices_and_illegal_characters ( input : & BStr ) -> Option < component:: Error > {
128
- let in3 = input. get ( ..3 ) ?;
127
+ /// Return `true` if the path component at `input` looks like a Windows device, like `CON`
128
+ /// or `LPT1` (case-insensitively).
129
+ ///
130
+ /// This is relevant only on Windows, where one may be tricked into reading or writing to such devices.
131
+ /// When reading from `CON`, a console-program may block until the user provided input.
132
+ pub fn component_is_windows_device ( input : & BStr ) -> bool {
133
+ is_win_device ( input)
134
+ }
135
+
136
+ fn is_win_device ( input : & BStr ) -> bool {
137
+ let Some ( in3) = input. get ( ..3 ) else { return false } ;
129
138
if in3. eq_ignore_ascii_case ( b"AUX" ) && is_done_windows ( input. get ( 3 ..) ) {
130
- return Some ( component :: Error :: WindowsReservedName ) ;
139
+ return true ;
131
140
}
132
141
if in3. eq_ignore_ascii_case ( b"NUL" ) && is_done_windows ( input. get ( 3 ..) ) {
133
- return Some ( component :: Error :: WindowsReservedName ) ;
142
+ return true ;
134
143
}
135
144
if in3. eq_ignore_ascii_case ( b"PRN" ) && is_done_windows ( input. get ( 3 ..) ) {
136
- return Some ( component :: Error :: WindowsReservedName ) ;
145
+ return true ;
137
146
}
138
147
// Note that the following allows `COM0`, even though `LPT0` is not allowed.
139
148
// Even though tests seem to indicate that neither `LPT0` nor `COM0` are valid
@@ -145,19 +154,26 @@ fn check_win_devices_and_illegal_characters(input: &BStr) -> Option<component::E
145
154
&& input. get ( 3 ) . map_or ( false , |n| * n >= b'1' && * n <= b'9' )
146
155
&& is_done_windows ( input. get ( 4 ..) )
147
156
{
148
- return Some ( component :: Error :: WindowsReservedName ) ;
157
+ return true ;
149
158
}
150
159
if in3. eq_ignore_ascii_case ( b"LPT" )
151
160
&& input. get ( 3 ) . map_or ( false , u8:: is_ascii_digit)
152
161
&& is_done_windows ( input. get ( 4 ..) )
153
162
{
154
- return Some ( component :: Error :: WindowsReservedName ) ;
163
+ return true ;
155
164
}
156
165
if in3. eq_ignore_ascii_case ( b"CON" )
157
166
&& ( is_done_windows ( input. get ( 3 ..) )
158
167
|| ( input. get ( 3 ..6 ) . map_or ( false , |n| n. eq_ignore_ascii_case ( b"IN$" ) ) && is_done_windows ( input. get ( 6 ..) ) )
159
168
|| ( input. get ( 3 ..7 ) . map_or ( false , |n| n. eq_ignore_ascii_case ( b"OUT$" ) ) && is_done_windows ( input. get ( 7 ..) ) ) )
160
169
{
170
+ return true ;
171
+ }
172
+ false
173
+ }
174
+
175
+ fn check_win_devices_and_illegal_characters ( input : & BStr ) -> Option < component:: Error > {
176
+ if is_win_device ( input) {
161
177
return Some ( component:: Error :: WindowsReservedName ) ;
162
178
}
163
179
if input. iter ( ) . any ( |b| * b < 0x20 || b":<>\" |?*" . contains ( b) ) {
0 commit comments