Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Regexp/Parser/Handlers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,10 @@ sub init {
if ($S->can($posix)) { $$ret = $S->$posix($neg, $how) }
else { $S->error($S->RPe_BADPOS, "$how$neg$name$how") }
}
elsif (&Rf & 0x200 and ${&Rx} =~ m{ \G [ \t]+ }xgc) {
# /xx: skip unescaped spaces and tabs inside character classes (Perl 5.26+)
redo;
}
elsif (${&Rx} =~ m{ \G (.) }xgcs) {
$$ret = $S->force_object(anyof_char => $1);
}
Expand Down
26 changes: 25 additions & 1 deletion t/08regex_flags.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use Test::More tests => 18;
use Test::More tests => 30;
use Regexp::Parser;
ok(1);

Expand Down Expand Up @@ -46,6 +46,30 @@ $w = $r->walker;
($n) = $w->();
is( $n->type, 'mbol', '/m makes ^ match \\n boundaries' );

# Test 8: /xx flag strips spaces and tabs inside character classes (Perl 5.26+)
ok( $r->regex('[a b c]', 'xx') );
is( $r->visual, '[abc]', 'xx flag strips spaces in char class' );

# Test 9: /xx flag does not strip newlines inside character classes
ok( $r->regex("[a\nb]", 'xx') );
is( $r->visual, "[a\nb]", 'xx flag preserves newlines in char class' );

# Test 10: /xx flag strips tabs inside character classes
ok( $r->regex("[a\tb]", 'xx') );
is( $r->visual, '[ab]', 'xx flag strips tabs in char class' );

# Test 11: /x flag does NOT strip spaces inside character classes
ok( $r->regex('[a b]', 'x') );
is( $r->visual, '[a b]', 'x flag preserves spaces in char class' );

# Test 12: inline (?xx:) strips spaces inside character classes
ok( $r->regex('(?xx:[a b c])') );
is( $r->visual, '(?xx:[abc])', 'inline (?xx:) strips spaces in char class' );

# Test 13: /xx escaping -- backslash-space is kept
ok( $r->regex('[a\\ b]', 'xx') );
is( $r->visual, '[a\ b]', 'xx flag preserves escaped space in char class' );

__DATA__
0 exact exactf abc
---
Loading