@@ -1877,30 +1877,33 @@ pub enum IsQuoted {
18771877}
18781878
18791879/// Expands a brace expansion into a vector of strings
1880- fn expand_braces ( brace_expansion : & BraceExpansion ) -> Result < Vec < String > , Error > {
1880+ fn expand_braces (
1881+ brace_expansion : & BraceExpansion ,
1882+ ) -> Result < Vec < String > , Error > {
18811883 match brace_expansion {
1882- BraceExpansion :: List ( elements) => {
1883- Ok ( elements. clone ( ) )
1884- }
1884+ BraceExpansion :: List ( elements) => Ok ( elements. clone ( ) ) ,
18851885 BraceExpansion :: Sequence { start, end, step } => {
18861886 expand_sequence ( start, end, step. as_ref ( ) )
18871887 }
18881888 }
18891889}
18901890
18911891/// Expands a sequence like {1..10} or {a..z} or {1..10..2}
1892- fn expand_sequence ( start : & str , end : & str , step : Option < & i32 > ) -> Result < Vec < String > , Error > {
1892+ fn expand_sequence (
1893+ start : & str ,
1894+ end : & str ,
1895+ step : Option < & i32 > ,
1896+ ) -> Result < Vec < String > , Error > {
18931897 // Try to parse as integers first
1894- if let ( Ok ( start_num) , Ok ( end_num) ) = ( start. parse :: < i32 > ( ) , end. parse :: < i32 > ( ) ) {
1898+ if let ( Ok ( start_num) , Ok ( end_num) ) =
1899+ ( start. parse :: < i32 > ( ) , end. parse :: < i32 > ( ) )
1900+ {
18951901 let is_reverse = start_num > end_num;
1896- let mut step_val = step. copied ( ) . unwrap_or ( if is_reverse { -1 } else { 1 } ) ;
1902+ let mut step_val =
1903+ step. copied ( ) . unwrap_or ( if is_reverse { -1 } else { 1 } ) ;
18971904
1898- // If step is provided and direction is reverse, negate the step
1899- if step. is_some ( ) && is_reverse && step_val > 0 {
1900- step_val = -step_val;
1901- }
1902- // If step is provided and direction is forward, ensure step is positive
1903- else if step. is_some ( ) && !is_reverse && step_val < 0 {
1905+ // If step is provided and its sign doesn't match the direction, flip it
1906+ if step. is_some ( ) && ( is_reverse != ( step_val < 0 ) ) {
19041907 step_val = -step_val;
19051908 }
19061909
@@ -1929,14 +1932,14 @@ fn expand_sequence(start: &str, end: &str, step: Option<&i32>) -> Result<Vec<Str
19291932 let start_char = start. chars ( ) . next ( ) . unwrap ( ) ;
19301933 let end_char = end. chars ( ) . next ( ) . unwrap ( ) ;
19311934 let is_reverse = start_char > end_char;
1932- let mut step_val = step. copied ( ) . unwrap_or ( if is_reverse { -1 } else { 1 } ) ;
1935+ let mut step_val =
1936+ step. copied ( ) . unwrap_or ( if is_reverse { -1 } else { 1 } ) ;
19331937
19341938 // If step is provided and direction is reverse, negate the step
1935- if step. is_some ( ) && is_reverse && step_val > 0 {
1936- step_val = -step_val;
1937- }
1938- // If step is provided and direction is forward, ensure step is positive
1939- else if step. is_some ( ) && !is_reverse && step_val < 0 {
1939+ // Or if step is provided and direction is forward, ensure step is positive
1940+ if step. is_some ( ) && ( is_reverse && step_val > 0 )
1941+ || ( !is_reverse && step_val < 0 )
1942+ {
19401943 step_val = -step_val;
19411944 }
19421945
@@ -1961,8 +1964,7 @@ fn expand_sequence(start: &str, end: &str, step: Option<&i32>) -> Result<Vec<Str
19611964 }
19621965 }
19631966 Ok ( result)
1964- }
1965- else {
1967+ } else {
19661968 // If it's not a valid sequence, return it as-is (bash behavior)
19671969 Ok ( vec ! [ format!( "{{{}..{}}}" , start, end) ] )
19681970 }
@@ -2197,9 +2199,10 @@ fn evaluate_word_parts(
21972199 WordPart :: BraceExpansion ( brace_expansion) => {
21982200 let expanded = expand_braces ( & brace_expansion) ?;
21992201 Ok ( Some ( Text :: new (
2200- expanded. into_iter ( )
2201- . map ( |s| TextPart :: Text ( s) )
2202- . collect ( )
2202+ expanded
2203+ . into_iter ( )
2204+ . map ( TextPart :: Text )
2205+ . collect ( ) ,
22032206 ) ) )
22042207 }
22052208 } ;
0 commit comments