ducminh-phan / reformat-gherkin

Formatter for Gherkin language
MIT License
22 stars 13 forks source link

Pipe characters are not escaped in tables #21

Closed rayjolt closed 4 years ago

rayjolt commented 4 years ago

I just tried running autoformat-gherkin on a feature file with an escaped pipe in a table cell, and it raised an internal error. Here is the feature file:

Feature: Feature name

    Scenario: Scenario name
        Given foo
        | header1  | header2 |
            | row \| 1 | row 2   |
        When bar
        Then baz

Here is the command I used, with the full output:

$ reformat-gherkin .
Error: cannot format /path/to/test.feature: INTERNAL ERROR: Invalid file contents are produced:
Parser errors:
(6:7): inconsistent cell count within the table
Please report a bug on https://github.com/ducminh-phan/reformat-gherkin/issues.
This invalid output might be helpful:
/tmp/rfmt-ghk_fllmdhek.log

All done! πŸ’₯ πŸ’” πŸ’₯
1 file failed to reformat.

And here is the contents of /tmp/rfmt-ghk_fllmdhek.log:

  File "/home/jack/projects/python/reformat-gherkin/reformat_gherkin/core.py", line 130, in assert_equivalent
    dst_ast = parse(dst)
  File "/home/jack/projects/python/reformat-gherkin/reformat_gherkin/parser.py", line 53, in parse
    raise InvalidInput(e) from e
Feature: Feature name

  Scenario: Scenario name
    Given foo
      | header1 | header2 |
      | row | 1 | row 2   |
    When bar
    Then baz

The problem is that the pipe inside the table cell is not escaped in the formatted output, causing a mismatched number of table cells.

Reformat-gherkin version: latest develop (ec19f9ca9c2fcbe8160a30e3f3c5fe748f8fbdf1) Python version: 3.7.4

rayjolt commented 4 years ago

I can't work on this right away, so others should feel free to pick it up. If I manage to find time, I'll leave another message here.

ducminh-phan commented 4 years ago

Thanks for reporting @rayjolt Since you are busy, I have just self-assigned this issue.