File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
src/uucore/src/lib/parser Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,11 @@ fn fix_negation(glob: &str) -> String {
1818 while i + 3 < chars. len ( ) {
1919 if chars[ i] == '[' && chars[ i + 1 ] == '^' {
2020 match chars[ i + 3 ..] . iter ( ) . position ( |x| * x == ']' ) {
21- None => ( ) ,
21+ None => {
22+ // if closing square bracket not found, stop looking for it
23+ // again
24+ break ;
25+ }
2226 Some ( j) => {
2327 chars[ i + 1 ] = '!' ;
2428 i += j + 4 ;
@@ -90,6 +94,11 @@ mod tests {
9094 assert_eq ! ( fix_negation( "[[]] [^a]" ) , "[[]] [!a]" ) ;
9195 assert_eq ! ( fix_negation( "[[] [^a]" ) , "[[] [!a]" ) ;
9296 assert_eq ! ( fix_negation( "[]] [^a]" ) , "[]] [!a]" ) ;
97+
98+ // test that we don't look for closing square brackets unnecessarily
99+ // Verifies issue #5584
100+ let teststring = std:: iter:: repeat ( "^[" ) . take ( 174571 ) . collect :: < String > ( ) ;
101+ assert_eq ! ( fix_negation( teststring. as_str( ) ) , teststring) ;
93102 }
94103
95104 #[ test]
You can’t perform that action at this time.
0 commit comments