@@ -197,7 +197,7 @@ impl Comments {
197
197
':' | ' ' => args. as_str ( ) ,
198
198
_ => bail ! ( "expected space or `:`, got `{next}`" ) ,
199
199
} ;
200
- ( command, args)
200
+ ( command, args. trim ( ) )
201
201
}
202
202
} ;
203
203
@@ -217,12 +217,37 @@ impl Comments {
217
217
self . env_vars . push ( ( k. to_string ( ) , v. to_string ( ) ) ) ;
218
218
} ,
219
219
"normalize-stderr-test" => {
220
- let ( from, to) = args
221
- . split_once ( "->" )
222
- . ok_or_else ( || eyre ! ( "normalize-stderr-test needs a `->`" ) ) ?;
223
- let from = from. trim ( ) . trim_matches ( '"' ) ;
224
- let to = to. trim ( ) . trim_matches ( '"' ) ;
225
- let from = Regex :: new ( from) . ok ( ) . ok_or_else ( || eyre ! ( "invalid regex" ) ) ?;
220
+ fn parse_str ( s : & str ) -> Result < ( & str , & str ) > {
221
+ let mut chars = s. char_indices ( ) ;
222
+ match chars. next ( ) . ok_or_else ( || eyre ! ( "missing arguments" ) ) ?. 1 {
223
+ '"' => {
224
+ let s = chars. as_str ( ) ;
225
+ let mut escaped = false ;
226
+ for ( i, c) in chars {
227
+ if escaped {
228
+ escaped = false ;
229
+ } else if c == '"' {
230
+ return Ok ( ( & s[ ..( i - 1 ) ] , s[ i..] . trim_start ( ) ) )
231
+ } else {
232
+ escaped = c == '\\' ;
233
+ }
234
+ }
235
+ bail ! ( "no closing quotes found for {s}" )
236
+ }
237
+ c => bail ! ( "expected '\" ', got {c}" ) ,
238
+ }
239
+ }
240
+
241
+ let ( from, rest) = parse_str ( args) ?;
242
+
243
+ let to = rest. strip_prefix ( "->" ) . ok_or_else ( || {
244
+ eyre ! ( "normalize-stderr-test needs a pattern and replacement separated by `->`" )
245
+ } ) ?. trim_start ( ) ;
246
+ let ( to, rest) = parse_str ( to) ?;
247
+
248
+ ensure ! ( rest. is_empty( ) , "trailing text after pattern replacement: {rest}" ) ;
249
+
250
+ let from = Regex :: new ( from) ?;
226
251
self . normalize_stderr . push ( ( from, to. to_string ( ) ) ) ;
227
252
}
228
253
"error-pattern" => {
0 commit comments