@@ -303,13 +303,15 @@ where
303
303
304
304
// Check if parsed quantifier is valid
305
305
let re = Regex :: new ( r"^(\d*,\d*|\d+)$" ) . expect ( "valid regular expression" ) ;
306
+ let is_natural_number = |string : & str | string. chars ( ) . all ( |x| x. is_ascii_digit ( ) ) ;
306
307
if let Some ( captures) = re. captures ( & quantifier) {
307
308
let matched = captures. at ( 0 ) . unwrap_or_default ( ) ;
308
309
match matched. split_once ( ',' ) {
309
310
Some ( ( "" , "" ) ) => Ok ( ( ) ) ,
310
311
Some ( ( x, "" ) ) | Some ( ( "" , x) ) => match x. parse :: < i32 > ( ) {
311
312
Ok ( x) if x <= i16:: MAX . into ( ) => Ok ( ( ) ) ,
312
313
Ok ( _) => Err ( ExprError :: TooBigRangeQuantifierIndex ) ,
314
+ Err ( _) if is_natural_number ( x) => Err ( ExprError :: TooBigRangeQuantifierIndex ) ,
313
315
Err ( _) => Err ( ExprError :: InvalidBracketContent ) ,
314
316
} ,
315
317
Some ( ( f, l) ) => match ( f. parse :: < i32 > ( ) , l. parse :: < i32 > ( ) ) {
@@ -318,11 +320,13 @@ where
318
320
Err ( ExprError :: TooBigRangeQuantifierIndex )
319
321
}
320
322
( Ok ( _) , Ok ( _) ) => Ok ( ( ) ) ,
323
+ _ if is_natural_number ( l) => Err ( ExprError :: TooBigRangeQuantifierIndex ) ,
321
324
_ => Err ( ExprError :: InvalidBracketContent ) ,
322
325
} ,
323
326
None => match matched. parse :: < i32 > ( ) {
324
327
Ok ( x) if x <= i16:: MAX . into ( ) => Ok ( ( ) ) ,
325
328
Ok ( _) => Err ( ExprError :: TooBigRangeQuantifierIndex ) ,
329
+ Err ( _) if is_natural_number ( matched) => Err ( ExprError :: TooBigRangeQuantifierIndex ) ,
326
330
Err ( _) => Err ( ExprError :: InvalidBracketContent ) ,
327
331
} ,
328
332
}
0 commit comments