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

Additional error handling edge cases #356

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
- [.NET] Improved parsing time
- [.NET] Use string-ordinal comparison consistently and remove old Mono workaround
- [.NET] Improved startup time
- [c] Optimise error handling for empty datatable rows
- [Perl] Optimise error handling for unclosed DocStrings

### Changed
- [cpp] add generic support for ABI versioning with VERSION ([#328](https://github.com/cucumber/gherkin/pull/328))
Expand Down
13 changes: 9 additions & 4 deletions c/src/gherkin_line.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,22 @@ wchar_t* GherkinLine_copy_line_text(const GherkinLine* line, int indent_to_remov

const Items* GherkinLine_table_cells(const GherkinLine* line) {
int item_count = calculate_cell_count(line->trimmed_line);
if (item_count == 0)
return (Items*)0;
Items* item_array = (Items*)malloc(sizeof(Items));
item_array->count = item_count;

if (item_count == 0) {
item_array->items = 0;
return item_array;
}

Span* items = (Span*)malloc(item_count * sizeof(Span));
int i;
for (i = 0; i < item_count; ++i) {
items[i].column = 0;
items[i].text = 0;
}
Items* item_array = (Items*)malloc(sizeof(Items));
item_array->count = item_count;
item_array->items = items;

const wchar_t* current_pos = line->trimmed_line;
for (i = 0; i < item_count; ++i) {
current_pos = populate_cell_data(&items[i], current_pos, current_pos - line->line_text);
Expand Down
3 changes: 3 additions & 0 deletions perl/lib/Gherkin/TokenMatcher.pm
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ sub match_StepLine {

sub match_DocStringSeparator {
my ( $self, $token ) = @_;
if ($token->is_eof) {
return 0;
}
if ( !$self->_active_doc_string_separator ) {
return $self->_match_DocStringSeparator( $token, '"""', 1 )
|| $self->_match_DocStringSeparator( $token, '```', 1 );
Expand Down
5 changes: 5 additions & 0 deletions testdata/bad/backslash_at_end_of_line_in_DataTable.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: Addition
Scenario: Add two numbers
When I press
| foo |
| bar \
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"parseError":{"message":"(5:3): inconsistent cell count within the table","source":{"location":{"column":3,"line":5},"uri":"../testdata/bad/backslash_at_end_of_line_in_DataTable.feature"}}}
4 changes: 4 additions & 0 deletions testdata/bad/file_ends_with_open_docstring.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Feature: Addition
Scenario: Add two numbers
Given I have added
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"parseError":{"message":"(5:0): unexpected end of file, expected: #DocStringSeparator, #Other","source":{"location":{"line":5},"uri":"../testdata/bad/file_ends_with_open_docstring.feature"}}}
2 changes: 2 additions & 0 deletions testdata/bad/unexpected_end_of_file.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Feature: Addition
@tag
1 change: 1 addition & 0 deletions testdata/bad/unexpected_end_of_file.feature.errors.ndjson
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"parseError":{"message":"(3:0): unexpected end of file, expected: #TagLine, #RuleLine, #Comment, #Empty","source":{"location":{"line":3},"uri":"../testdata/bad/unexpected_end_of_file.feature"}}}
5 changes: 5 additions & 0 deletions testdata/bad/unfinished_DataTable.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: Addition
Scenario: Add two numbers
When I press
| foo |
| bar
1 change: 1 addition & 0 deletions testdata/bad/unfinished_DataTable.feature.errors.ndjson
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"parseError":{"message":"(5:3): inconsistent cell count within the table","source":{"location":{"column":3,"line":5},"uri":"../testdata/bad/unfinished_DataTable.feature"}}}
Loading