@@ -1033,9 +1033,8 @@ sub _random_from_class {
10331033 my @chars ;
10341034
10351035 # Debugging this regex: qr/!#-'*+\\-\\.\\^_`|~0-9A-Za-z/
1036- # which gives this error: 'Argument "#" isn't numeric in range (or flop)'
1037- # DEBUG
1038- warn " DEBUG: class = '$class ', length = " , length ($class );
1036+ # which used to give this error: 'Argument "#" isn't numeric in range (or flop)'
1037+ warn " DEBUG: class = '$class ', length = " , length ($class ) if ($ENV {DEBUG_REGEX_GEN });
10391038
10401039 # Handle negation
10411040 my $negate = 0;
@@ -1049,13 +1048,12 @@ sub _random_from_class {
10491048 while ($i < length ($class )) {
10501049 my $char = substr ($class , $i , 1);
10511050
1052- # DEBUG
1053- warn " DEBUG: i=$i , char='$char ' (ord=" , ord ($char ), ' )' ;
1051+ warn " DEBUG: i=$i , char='$char ' (ord=" , ord ($char ), ' )' if ($ENV {DEBUG_REGEX_GEN });
10541052
10551053 if ($char eq ' \\ ' ) {
10561054 $i ++;
10571055 my $next = substr ($class , $i , 1);
1058- warn " DEBUG: Escaped char: $next " ;
1056+ warn " DEBUG: Escaped char: $next " if ( $ENV { DEBUG_REGEX_GEN }) ;
10591057 if ($next eq ' d' ) {
10601058 push @chars , (' 0' ..' 9' );
10611059 } elsif ($next eq ' w' ) {
@@ -1072,23 +1070,22 @@ sub _random_from_class {
10721070 # Escaped literal character (including \-, \., \^, etc.)
10731071 push @chars , $next ;
10741072 }
1075- } elsif ($i + 2 < length ($class ) && substr ($class , $i +1, 1) eq ' -' && substr ($class , $i +2, 1) ne ' ]' ) {
1076- # Range (but not if - is at end or before ])
1077- my $next_char = substr ($class , $i +1, 1); # Potential range
1073+ } elsif ($i + 2 < length ($class ) && substr ($class , $i +1, 1) eq ' -' ) {
1074+ # Potential range
10781075 my $end_char = substr ($class , $i +2, 1);
10791076
1080- warn " DEBUG: Potential range: '$char ' - '$end_char '" ;
1081-
1082- # Skip if end_char is a backslash (escaped char follows)
1083- if ($end_char eq ' \\ ' ) {
1077+ # Check if end is escaped or if this is valid range
1078+ if ($end_char eq ' \\ ' || $end_char eq ' ]' ) {
1079+ # Not a range, dash is literal
10841080 push @chars , $char ;
10851081 } elsif (ord ($end_char ) >= ord ($char )) {
1086- # Valid range
1087- warn " DEBUG: Valid range from " , ord ($char ), ' to ' , ord ($end_char );
1088- push @chars , ($char .. $end_char );
1082+ # Valid range - use ord/chr to avoid quote interpolation issues
1083+ my $start_ord = ord ($char );
1084+ my $end_ord = ord ($end_char );
1085+ push @chars , map { chr ($_ ) } ($start_ord .. $end_ord );
10891086 $i += 2; # Will be incremented again by loop, total +3
10901087 } else {
1091- # Invalid range, treat as literals
1088+ # Invalid range order
10921089 push @chars , $char ;
10931090 }
10941091 } else {
@@ -1097,7 +1094,7 @@ sub _random_from_class {
10971094 $i ++;
10981095 }
10991096
1100- warn ' DEBUG: Final chars array has ' , scalar (@chars ), ' elements' ;
1097+ warn ' DEBUG: Final chars array has ' , scalar (@chars ), ' elements' if ( $ENV { DEBUG_REGEX_GEN }) ;
11011098
11021099 if ($negate ) {
11031100 my %excluded = map { $_ => 1 } @chars ;
0 commit comments