Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt

## [Unreleased]
### Fixed
- Provide trailing space in Irish keywords ([#243](https://github.com/cucumber/gherkin/pull/243))
- Tamil "And" and "But" translations should have single trailing space ([#243](https://github.com/cucumber/gherkin/pull/243))
- [Python] Provide informative exception for trailing escapes in tables ([#241](https://github.com/cucumber/gherkin/pull/241))
- (i18n) Provide trailing space in Irish keywords ([#243](https://github.com/cucumber/gherkin/pull/243))
- (i18n) Tamil "And" and "But" translations should have single trailing space ([#243](https://github.com/cucumber/gherkin/pull/243))

## [28.0.0] - 2024-02-15
### Added
Expand Down
2 changes: 1 addition & 1 deletion python/gherkin/gherkin_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def split_table_cells(self, row):
cell = ''
start_col = col + 1
elif char == '\\':
char = next(row)
char = next(row, "")
mpkorstanje marked this conversation as resolved.
Show resolved Hide resolved
col += 1
if char == 'n':
cell += '\n'
Expand Down
17 changes: 16 additions & 1 deletion python/test/gherkin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from gherkin.token_scanner import TokenScanner
from gherkin.token_matcher import TokenMatcher
from gherkin.parser import Parser
from gherkin.errors import ParserError
from gherkin.errors import CompositeParserException, ParserError
import pytest


Expand Down Expand Up @@ -89,3 +89,18 @@ def test_change_the_default_language():
}

assert expected == feature_file

@pytest.mark.parametrize("trailing_text", ["\\", "\\ "])
def test_inconsistent_cell_count_with_trailing_escape(trailing_text):
feature_text = """Feature:
Scenario:
Given I have a table
| Name | Value |
| A | """ + trailing_text
parser = Parser()

with pytest.raises(
CompositeParserException,
match="inconsistent cell count within the table",
mpkorstanje marked this conversation as resolved.
Show resolved Hide resolved
):
parser.parse(TokenScanner(feature_text))