cucumber / gherkin

A parser and compiler for the Gherkin language.
MIT License
160 stars 48 forks source link

A space following Escape \ as the last character of a table line instead of | causes StopIterationError not CompositeError #223

Closed isparks-tg closed 2 months ago

isparks-tg commented 4 months ago

πŸ‘“ What did you see?

A table of the form

Some step with table:
    | Name | Value |
    | A        | 1        \

Where a SPACE follows the last \ (if the space is not present then the error does not exhibit)

Python example:

from gherkin.parser import Parser
from gherkin.token_scanner import TokenScanner

feature_text = """
Feature: As a developer I want to report a bug

   Scenario: Bad table escape
      When I have a table
         | Name | Value |
         | A    |       \ """
                        # ^- Note space
parser = Parser()
parser.parse(TokenScanner(feature_text))

Will fail the parser because of StopIteration.

βœ… What did you expect to see?

A CompositeParserException raised with position of error - which is what is seen if the space is removed

πŸ“¦ Which tool/library version are you using?

python gherkin_official-4.1.3 but I believe exists in current github code also related to split_table_cells in gherkin_line.py

πŸ”¬ How could we reproduce it?

Steps to reproduce the behavior:

  1. Install gherkin-official.' version 'gherkin_official-4.1.3'
  2. Create a file called 'gherkin_test.py' with the contents above
  3. python gherkin_test.py
  4. See error 'RuntimeError: generator raised StopIteration'
mpkorstanje commented 4 months ago

Oh nice find. Would you be interested in creating a PR to fix this? We currently don't have a maintainer with a lot of experience in Python.