Skip to content

Commit

Permalink
Perl, .Net: provide informative exception for trailing escapes in tab…
Browse files Browse the repository at this point in the history
…les (#245)
  • Loading branch information
mpkorstanje authored Jul 8, 2024
1 parent 20e23cb commit 89b7199
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt

## [Unreleased]
### Fixed
- [.NET] Provide informative exception for trailing escapes in tables ([#245](https://github.com/cucumber/gherkin/pull/245))
- [Perl] Provide informative exception for trailing escapes in tables ([#245](https://github.com/cucumber/gherkin/pull/245))
- [Ruby] Provide informative exception for trailing escapes in tables ([#244](https://github.com/cucumber/gherkin/pull/244))
- [Python] Provide informative exception for trailing escapes in tables ([#241](https://github.com/cucumber/gherkin/pull/241))
- (i18n) Provide trailing space in Irish step keywords ([#243](https://github.com/cucumber/gherkin/pull/243))
Expand Down
21 changes: 12 additions & 9 deletions dotnet/Gherkin/GherkinLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,19 @@ private IEnumerable<Tuple<string, int>> SplitCells(string row)
cell = "";
startPos = pos;
} else if (c == GherkinLanguageConstants.TABLE_CELL_ESCAPE_CHAR) {
rowEnum.MoveNext();
pos++;
c = rowEnum.Current;
if (c == GherkinLanguageConstants.TABLE_CELL_NEWLINE_ESCAPE) {
cell += "\n";
} else {
if (c.ToString() != GherkinLanguageConstants.TABLE_CELL_SEPARATOR && c != GherkinLanguageConstants.TABLE_CELL_ESCAPE_CHAR) {
cell += GherkinLanguageConstants.TABLE_CELL_ESCAPE_CHAR;
if(rowEnum.MoveNext()) {
pos++;
c = rowEnum.Current;
if (c == GherkinLanguageConstants.TABLE_CELL_NEWLINE_ESCAPE) {
cell += "\n";
} else {
if (c.ToString() != GherkinLanguageConstants.TABLE_CELL_SEPARATOR && c != GherkinLanguageConstants.TABLE_CELL_ESCAPE_CHAR) {
cell += GherkinLanguageConstants.TABLE_CELL_ESCAPE_CHAR;
}
cell += c;
}
cell += c;
} else {
cell += GherkinLanguageConstants.TABLE_CELL_ESCAPE_CHAR;
}
} else {
cell += c;
Expand Down
9 changes: 6 additions & 3 deletions perl/lib/Gherkin/Line.pm
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,12 @@ sub _split_table_cells_iterator {
return ( $cell, $start_col );
}
} elsif ( $char eq "\\" ) {
$row =~ s/^(.)// || die "Unpossible";
$col += 1;
$cell .= '\\' . $1;
if ($row =~ s/^(.)//) {
$col += 1;
$cell .= '\\' . $1;
} else {
$cell .= '\\';
}
} elsif ( defined $char ) {
$cell .= $char;
} else {
Expand Down
12 changes: 12 additions & 0 deletions testdata/good/extra_table_content.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Feature: Extra table content
Tables are delimited by pipes on both sides.
Anything that isn't enclosed is not part of
the table.

It is not recommended to use this feature, but
it is how the implementation currently works.

Scenario: We're a bit extra
Given a pirate crew
| Luffy | Zorro | Doflamingo \
| Nami | Brook | BlackBeard
1 change: 1 addition & 0 deletions testdata/good/extra_table_content.feature.ast.ndjson
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"gherkinDocument": {"comments": [], "feature": {"children": [{"scenario": {"description": "", "examples": [], "id": "3", "keyword": "Scenario", "location": {"column": 3, "line": 9}, "name": "We're a bit extra", "steps": [{"dataTable": {"location": {"column": 7, "line": 11}, "rows": [{"cells": [{"location": {"column": 9, "line": 11}, "value": "Luffy"}, {"location": {"column": 17, "line": 11}, "value": "Zorro"}], "id": "0", "location": {"column": 7, "line": 11}}, {"cells": [{"location": {"column": 9, "line": 12}, "value": "Nami"}, {"location": {"column": 17, "line": 12}, "value": "Brook"}], "id": "1", "location": {"column": 7, "line": 12}}]}, "id": "2", "keyword": "Given ", "keywordType": "Context", "location": {"column": 5, "line": 10}, "text": "a pirate crew"}], "tags": []}}], "description": " Tables are delimited by pipes on both sides.\n Anything that isn't enclosed is not part of\n the table.\n\n It is not recommended to use this feature, but\n it is how the implementation currently works.", "keyword": "Feature", "language": "en", "location": {"column": 1, "line": 1}, "name": "Extra table content", "tags": []}, "uri": "../testdata/good/extra_table_content.feature"}}
1 change: 1 addition & 0 deletions testdata/good/extra_table_content.feature.pickles.ndjson
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"pickle": {"astNodeIds": ["3"], "id": "5", "language": "en", "name": "We're a bit extra", "steps": [{"argument": {"dataTable": {"rows": [{"cells": [{"value": "Luffy"}, {"value": "Zorro"}]}, {"cells": [{"value": "Nami"}, {"value": "Brook"}]}]}}, "astNodeIds": ["2"], "id": "4", "text": "a pirate crew", "type": "Context"}], "tags": [], "uri": "../testdata/good/extra_table_content.feature"}}
1 change: 1 addition & 0 deletions testdata/good/extra_table_content.feature.source.ndjson
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"source": {"data": "Feature: Extra table content\n Tables are delimited by pipes on both sides.\n Anything that isn't enclosed is not part of\n the table.\n\n It is not recommended to use this feature, but\n it is how the implementation currently works.\n\n Scenario: We're a bit extra\n Given a pirate crew\n | Luffy | Zorro | Doflamingo \\\n | Nami | Brook | BlackBeard\n", "mediaType": "text/x.cucumber.gherkin+plain", "uri": "../testdata/good/extra_table_content.feature"}}
13 changes: 13 additions & 0 deletions testdata/good/extra_table_content.feature.tokens
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(1:1)FeatureLine:()Feature/Extra table content/
(2:1)Other:/ Tables are delimited by pipes on both sides./
(3:1)Other:/ Anything that isn't enclosed is not part of/
(4:1)Other:/ the table./
(5:1)Other://
(6:1)Other:/ It is not recommended to use this feature, but/
(7:1)Other:/ it is how the implementation currently works./
(8:1)Other://
(9:3)ScenarioLine:()Scenario/We're a bit extra/
(10:5)StepLine:(Context)Given /a pirate crew/
(11:7)TableRow://9:Luffy,17:Zorro
(12:7)TableRow://9:Nami,17:Brook
EOF

0 comments on commit 89b7199

Please sign in to comment.