Skip to content

Commit

Permalink
[tag-expressions] Fix Perl handling of backslash escaping in tags
Browse files Browse the repository at this point in the history
The escaping backslash was added to the tag and if the escaped character
was a space, it was skipped even though being escaped.

Re #1778.
  • Loading branch information
ehuelsmann committed Oct 8, 2021
1 parent a508d30 commit 087f4ed
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
5 changes: 3 additions & 2 deletions tag-expressions/perl/lib/Cucumber/TagExpressions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ sub _get_token {
_save_token( $state, $char );
return $token;
}
$token .= $char unless $char =~ /\s/;

if ( $char eq "\\" ) {
$token .= _consume_char( $state );
}
else {
$token .= $char;
}
}
}
}
Expand Down
19 changes: 16 additions & 3 deletions tag-expressions/perl/t/02-evaluate.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ use Cucumber::TagExpressions;


my @good = (
{ expr => '@a\ or @b',
tests => [ { tags => [ '@a\ ' ], outcome => !!0 },
{ tags => [ '@a ' ], outcome => 1 },
{ tags => [ '@b' ], outcome => 1 },
{ tags => [ '@a' ], outcome => !!0 },
] },
{ expr => "\@a\\\\", tests => [] },
{ expr => '@a',
tests => [ { tags => [ qw/@a/ ], outcome => 1 },
{ tags => [ qw/@b/ ], outcome => !!0 },
Expand Down Expand Up @@ -70,11 +77,16 @@ my @good = (
{ tags => [ qw/@b @d/ ], outcome => 1 },
{ tags => [ qw/@q/ ], outcome => !!0 },
] },
{ expr => '@a\b',
tests => [ { tags => [ qw/@a\b/ ], outcome => 1 },
{ expr => "\@a\\b",
tests => [ { tags => [ "\@a\\b" ], outcome => !!0 },
{ tags => [ '@ab' ], outcome => 1 },
{ tags => [ qw/@a/ ], outcome => !!0 },
] },
{ expr => "\@a\\\\b",
tests => [ { tags => [ "\@a\\b" ], outcome => 1 },
{ tags => [ '@ab' ], outcome => !!0 },
{ tags => [ qw/@a/ ], outcome => !!0 },
] },

);

for my $ex (@good) {
Expand Down Expand Up @@ -102,6 +114,7 @@ my %bad_syntax = (
'@' => 'Tag must be longer than the at-sign',
'@a or @' => 'Tag must be longer than the at-sign',
'@a and @b)' => 'Junk at end of expression',
"\@a\\" => 'Unexpected end of string parsing tag expression',
);

for my $expr (keys %bad_syntax) {
Expand Down

0 comments on commit 087f4ed

Please sign in to comment.