@@ -70,6 +70,7 @@ extern crate doc_comment;
70
70
doctest ! ( "../README.md" ) ;
71
71
72
72
use std:: cmp;
73
+ use std:: cmp:: Ordering ;
73
74
use std:: error:: Error ;
74
75
use std:: fmt;
75
76
use std:: fs;
@@ -620,52 +621,56 @@ impl Pattern {
620
621
621
622
let count = i - old;
622
623
623
- if count > 2 {
624
- return Err ( PatternError {
625
- pos : old + 2 ,
626
- msg : ERROR_WILDCARDS ,
627
- } ) ;
628
- } else if count == 2 {
629
- // ** can only be an entire path component
630
- // i.e. a/**/b is valid, but a**/b or a/**b is not
631
- // invalid matches are treated literally
632
- let is_valid = if i == 2 || path:: is_separator ( chars[ i - count - 1 ] ) {
633
- // it ends in a '/'
634
- if i < chars. len ( ) && path:: is_separator ( chars[ i] ) {
635
- i += 1 ;
636
- true
637
- // or the pattern ends here
638
- // this enables the existing globbing mechanism
639
- } else if i == chars. len ( ) {
640
- true
641
- // `**` ends in non-separator
624
+ match count. cmp ( & 2 ) {
625
+ Ordering :: Greater => {
626
+ return Err ( PatternError {
627
+ pos : old + 2 ,
628
+ msg : ERROR_WILDCARDS ,
629
+ } )
630
+ }
631
+ Ordering :: Equal => {
632
+ // ** can only be an entire path component
633
+ // i.e. a/**/b is valid, but a**/b or a/**b is not
634
+ // invalid matches are treated literally
635
+ let is_valid = if i == 2 || path:: is_separator ( chars[ i - count - 1 ] ) {
636
+ // it ends in a '/'
637
+ if i < chars. len ( ) && path:: is_separator ( chars[ i] ) {
638
+ i += 1 ;
639
+ true
640
+ // or the pattern ends here
641
+ // this enables the existing globbing mechanism
642
+ } else if i == chars. len ( ) {
643
+ true
644
+ // `**` ends in non-separator
645
+ } else {
646
+ return Err ( PatternError {
647
+ pos : i,
648
+ msg : ERROR_RECURSIVE_WILDCARDS ,
649
+ } ) ;
650
+ }
651
+ // `**` begins with non-separator
642
652
} else {
643
653
return Err ( PatternError {
644
- pos : i ,
654
+ pos : old - 1 ,
645
655
msg : ERROR_RECURSIVE_WILDCARDS ,
646
656
} ) ;
647
- }
648
- // `**` begins with non-separator
649
- } else {
650
- return Err ( PatternError {
651
- pos : old - 1 ,
652
- msg : ERROR_RECURSIVE_WILDCARDS ,
653
- } ) ;
654
- } ;
657
+ } ;
655
658
656
- if is_valid {
657
- // collapse consecutive AnyRecursiveSequence to a
658
- // single one
659
+ if is_valid {
660
+ // collapse consecutive AnyRecursiveSequence to a
661
+ // single one
659
662
660
- let tokens_len = tokens. len ( ) ;
663
+ let tokens_len = tokens. len ( ) ;
661
664
662
- if !( tokens_len > 1 && tokens[ tokens_len - 1 ] == AnyRecursiveSequence ) {
663
- is_recursive = true ;
664
- tokens. push ( AnyRecursiveSequence ) ;
665
+ if !( tokens_len > 1
666
+ && tokens[ tokens_len - 1 ] == AnyRecursiveSequence )
667
+ {
668
+ is_recursive = true ;
669
+ tokens. push ( AnyRecursiveSequence ) ;
670
+ }
665
671
}
666
672
}
667
- } else {
668
- tokens. push ( AnySequence ) ;
673
+ Ordering :: Less => tokens. push ( AnySequence ) ,
669
674
}
670
675
}
671
676
'[' => {
@@ -1029,7 +1034,7 @@ fn chars_eq(a: char, b: char, case_sensitive: bool) -> bool {
1029
1034
true
1030
1035
} else if !case_sensitive && a. is_ascii ( ) && b. is_ascii ( ) {
1031
1036
// FIXME: work with non-ascii chars properly (issue #9084)
1032
- a. to_ascii_lowercase ( ) == b . to_ascii_lowercase ( )
1037
+ a. eq_ignore_ascii_case ( & b )
1033
1038
} else {
1034
1039
a == b
1035
1040
}
@@ -1166,8 +1171,7 @@ mod test {
1166
1171
. ok ( )
1167
1172
. and_then ( |p| match p. components ( ) . next ( ) . unwrap ( ) {
1168
1173
Component :: Prefix ( prefix_component) => {
1169
- let path = Path :: new ( prefix_component. as_os_str ( ) ) ;
1170
- path. join ( "*" ) ;
1174
+ let path = Path :: new ( prefix_component. as_os_str ( ) ) . join ( "*" ) ;
1171
1175
Some ( path. to_path_buf ( ) )
1172
1176
}
1173
1177
_ => panic ! ( "no prefix in this path" ) ,
0 commit comments