Skip to content

Commit

Permalink
Don't consume all of line when parsing tags
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaranmcnulty committed Feb 9, 2021
1 parent 14da412 commit bfc5d35
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Behat/Gherkin/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ protected function consumeLine()
$this->trimmedLine = null;
}

/**
* Consumes first part of line from input without incrementing the line number
*/
protected function consumeLineUntil(int $trimmedOffset)
{
$this->line = mb_substr(ltrim($this->line), $trimmedOffset, null, 'utf-8');
$this->trimmedLine = null;
}

/**
* Returns trimmed version of line.
*
Expand Down Expand Up @@ -502,17 +511,24 @@ protected function scanTableRow()
protected function scanTags()
{
$line = $this->getTrimmedLine();
$line = preg_replace('/\s+#.*$/', '', $line);

if (!isset($line[0]) || '@' !== $line[0]) {
return null;
}

if(preg_match('/^(?<line>.*)\s+#.*$/', $line, $matches)) {
['line' => $line] = $matches;
$this->consumeLineUntil(mb_strlen($line, 'utf-8'));
}
else {
$this->consumeLine();
}

$token = $this->takeToken('Tag');
$tags = explode('@', mb_substr($line, 1, mb_strlen($line, 'utf8') - 1, 'utf8'));
$tags = array_map('trim', $tags);
$token['tags'] = $tags;

$this->consumeLine();

return $token;
}
Expand Down

0 comments on commit bfc5d35

Please sign in to comment.