cucumber / gherkin

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

python: provide informative exception for trailing escapes in tables #241

Closed kieran-ryan closed 2 months ago

kieran-ryan commented 2 months ago

πŸ€” What's changed?

With the Python implementation:

  1. Whitespace either side of a table row is stripped.
  2. The table row is passed to a function to strip and yields its cell values
  3. Characters in each cell are iterated over to handle them appropriately, such as new columns (|), escape characters, etc.
  4. As escape characters are typically followed by a special character (e.g. n, t), when an escape character is detected \\ an additional next call is made to grab the next character
  5. As in step 1, whitespace after a trailing escape character (\\) would be stripped, there would not be a following character and a StopIteration error is raised.

https://github.com/cucumber/gherkin/blob/b055261c59f5f905fe637b230017054250c6ebb5/python/gherkin/gherkin_line.py#L39-L62

By defaulting the iterator to an empty string, when there is a trailing escape character, the trailing escape character will not trigger a StopIteration error and subsequent code will appropriately raise an inconsistent cell count error message.

⚑️ What's your motivation?

🏷️ What kind of change is this?

♻️ Anything particular you want feedback on?

πŸ“‹ Checklist:


This text was originally generated from a template, then edited by hand. You can modify the template here.

mpkorstanje commented 2 months ago

Not a problem in JS, while we do append undefined, this cell is never used because it is not terminated by a |.

image