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

gherkin: Escape triple backticks in alternative docstring #889

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions gherkin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
### Removed

### Fixed

* [JavaScript] `Gherkin#fromPaths` emits an error if a path can't be read (for example if it is a directory)

* [Java/JavaScript/Ruby/Go] Escape triple backticks in alternative docstring
([#889](https://github.com/cucumber/cucumber/pull/889)
[mpkorstanje])

## [9.2.0] - 2020-01-22

### Added
Expand Down Expand Up @@ -710,6 +712,7 @@ to Gherkin 2.
[merrua]: https://github.com/merrua
[milhcbt]: https://github.com/milhcbt
[moreau-nicolas]: https://github.com/moreau-nicolas
[mpkorstanje]: https://github.com/mpkorstanje
[nalekberov]: https://github.com/nalekberov
[nixel2007]: https://github.com/nixel2007
[nikolovski]: https://github.com/nikolovski
Expand Down
6 changes: 6 additions & 0 deletions gherkin/c/testdata/good/docstrings.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ Feature: DocString variations
\"\"\"
third line
"""
And a DocString with an escaped alternative separator inside
```
first line
\`\`\`
third line
```
19 changes: 18 additions & 1 deletion gherkin/c/testdata/good/docstrings.feature.ast.ndjson
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"children": [
{
"scenario": {
"id": "7",
"id": "8",
"keyword": "Scenario",
"location": {
"column": 3,
Expand Down Expand Up @@ -131,6 +131,23 @@
"line": 38
},
"text": "a DocString with escaped separator inside"
},
{
"docString": {
"content": "first line\n```\nthird line",
"delimiter": "```",
"location": {
"column": 7,
"line": 45
}
},
"id": "7",
"keyword": "And ",
"location": {
"column": 5,
"line": 44
},
"text": "a DocString with an escaped alternative separator inside"
}
]
}
Expand Down
30 changes: 21 additions & 9 deletions gherkin/c/testdata/good/docstrings.feature.pickles.ndjson
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"pickle": {
"astNodeIds": [
"7"
"8"
],
"id": "15",
"id": "17",
"language": "en",
"name": "minimalistic",
"steps": [
Expand All @@ -16,7 +16,7 @@
"astNodeIds": [
"0"
],
"id": "8",
"id": "9",
"text": "a simple DocString"
},
{
Expand All @@ -29,7 +29,7 @@
"astNodeIds": [
"1"
],
"id": "9",
"id": "10",
"text": "a DocString with content type"
},
{
Expand All @@ -41,7 +41,7 @@
"astNodeIds": [
"2"
],
"id": "10",
"id": "11",
"text": "a DocString with wrong indentation"
},
{
Expand All @@ -53,7 +53,7 @@
"astNodeIds": [
"3"
],
"id": "11",
"id": "12",
"text": "a DocString with alternative separator"
},
{
Expand All @@ -65,7 +65,7 @@
"astNodeIds": [
"4"
],
"id": "12",
"id": "13",
"text": "a DocString with normal separator inside"
},
{
Expand All @@ -77,7 +77,7 @@
"astNodeIds": [
"5"
],
"id": "13",
"id": "14",
"text": "a DocString with alternative separator inside"
},
{
Expand All @@ -89,8 +89,20 @@
"astNodeIds": [
"6"
],
"id": "14",
"id": "15",
"text": "a DocString with escaped separator inside"
},
{
"argument": {
"docString": {
"content": "first line\n```\nthird line"
}
},
"astNodeIds": [
"7"
],
"id": "16",
"text": "a DocString with an escaped alternative separator inside"
}
],
"uri": "testdata/good/docstrings.feature"
Expand Down
2 changes: 1 addition & 1 deletion gherkin/c/testdata/good/docstrings.feature.source.ndjson
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"data": "Feature: DocString variations\n\n Scenario: minimalistic\n Given a simple DocString\n \"\"\"\n first line (no indent)\n second line (indented with two spaces)\n\n third line was empty\n \"\"\"\n Given a DocString with content type\n \"\"\"xml\n <foo>\n <bar />\n </foo>\n \"\"\"\n And a DocString with wrong indentation\n \"\"\"\n wrongly indented line\n \"\"\"\n And a DocString with alternative separator\n ```\n first line\n second line\n ```\n And a DocString with normal separator inside\n ```\n first line\n \"\"\"\n third line\n ```\n And a DocString with alternative separator inside\n \"\"\"\n first line\n ```\n third line\n \"\"\"\n And a DocString with escaped separator inside\n \"\"\"\n first line\n \\\"\\\"\\\"\n third line\n \"\"\"\n",
"data": "Feature: DocString variations\n\n Scenario: minimalistic\n Given a simple DocString\n \"\"\"\n first line (no indent)\n second line (indented with two spaces)\n\n third line was empty\n \"\"\"\n Given a DocString with content type\n \"\"\"xml\n <foo>\n <bar />\n </foo>\n \"\"\"\n And a DocString with wrong indentation\n \"\"\"\n wrongly indented line\n \"\"\"\n And a DocString with alternative separator\n ```\n first line\n second line\n ```\n And a DocString with normal separator inside\n ```\n first line\n \"\"\"\n third line\n ```\n And a DocString with alternative separator inside\n \"\"\"\n first line\n ```\n third line\n \"\"\"\n And a DocString with escaped separator inside\n \"\"\"\n first line\n \\\"\\\"\\\"\n third line\n \"\"\"\n And a DocString with an escaped alternative separator inside\n ```\n first line\n \\`\\`\\`\n third line\n ```",
"mediaType": "text/x.cucumber.gherkin+plain",
"uri": "testdata/good/docstrings.feature"
}
Expand Down
6 changes: 6 additions & 0 deletions gherkin/c/testdata/good/docstrings.feature.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@
(41:1)Other:/"""/
(42:1)Other:/third line/
(43:7)DocStringSeparator:"""//
(44:5)StepLine:And /a DocString with an escaped alternative separator inside/
(45:7)DocStringSeparator:```//
(46:1)Other:/first line/
(47:1)Other:/```/
(48:1)Other:/third line/
(49:7)DocStringSeparator:```//
EOF
6 changes: 6 additions & 0 deletions gherkin/dotnet/testdata/good/docstrings.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ Feature: DocString variations
\"\"\"
third line
"""
And a DocString with an escaped alternative separator inside
```
first line
\`\`\`
third line
```
19 changes: 18 additions & 1 deletion gherkin/dotnet/testdata/good/docstrings.feature.ast.ndjson
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"children": [
{
"scenario": {
"id": "7",
"id": "8",
"keyword": "Scenario",
"location": {
"column": 3,
Expand Down Expand Up @@ -131,6 +131,23 @@
"line": 38
},
"text": "a DocString with escaped separator inside"
},
{
"docString": {
"content": "first line\n```\nthird line",
"delimiter": "```",
"location": {
"column": 7,
"line": 45
}
},
"id": "7",
"keyword": "And ",
"location": {
"column": 5,
"line": 44
},
"text": "a DocString with an escaped alternative separator inside"
}
]
}
Expand Down
30 changes: 21 additions & 9 deletions gherkin/dotnet/testdata/good/docstrings.feature.pickles.ndjson
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"pickle": {
"astNodeIds": [
"7"
"8"
],
"id": "15",
"id": "17",
"language": "en",
"name": "minimalistic",
"steps": [
Expand All @@ -16,7 +16,7 @@
"astNodeIds": [
"0"
],
"id": "8",
"id": "9",
"text": "a simple DocString"
},
{
Expand All @@ -29,7 +29,7 @@
"astNodeIds": [
"1"
],
"id": "9",
"id": "10",
"text": "a DocString with content type"
},
{
Expand All @@ -41,7 +41,7 @@
"astNodeIds": [
"2"
],
"id": "10",
"id": "11",
"text": "a DocString with wrong indentation"
},
{
Expand All @@ -53,7 +53,7 @@
"astNodeIds": [
"3"
],
"id": "11",
"id": "12",
"text": "a DocString with alternative separator"
},
{
Expand All @@ -65,7 +65,7 @@
"astNodeIds": [
"4"
],
"id": "12",
"id": "13",
"text": "a DocString with normal separator inside"
},
{
Expand All @@ -77,7 +77,7 @@
"astNodeIds": [
"5"
],
"id": "13",
"id": "14",
"text": "a DocString with alternative separator inside"
},
{
Expand All @@ -89,8 +89,20 @@
"astNodeIds": [
"6"
],
"id": "14",
"id": "15",
"text": "a DocString with escaped separator inside"
},
{
"argument": {
"docString": {
"content": "first line\n```\nthird line"
}
},
"astNodeIds": [
"7"
],
"id": "16",
"text": "a DocString with an escaped alternative separator inside"
}
],
"uri": "testdata/good/docstrings.feature"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"source": {
"data": "Feature: DocString variations\n\n Scenario: minimalistic\n Given a simple DocString\n \"\"\"\n first line (no indent)\n second line (indented with two spaces)\n\n third line was empty\n \"\"\"\n Given a DocString with content type\n \"\"\"xml\n <foo>\n <bar />\n </foo>\n \"\"\"\n And a DocString with wrong indentation\n \"\"\"\n wrongly indented line\n \"\"\"\n And a DocString with alternative separator\n ```\n first line\n second line\n ```\n And a DocString with normal separator inside\n ```\n first line\n \"\"\"\n third line\n ```\n And a DocString with alternative separator inside\n \"\"\"\n first line\n ```\n third line\n \"\"\"\n And a DocString with escaped separator inside\n \"\"\"\n first line\n \\\"\\\"\\\"\n third line\n \"\"\"\n",
"data": "Feature: DocString variations\n\n Scenario: minimalistic\n Given a simple DocString\n \"\"\"\n first line (no indent)\n second line (indented with two spaces)\n\n third line was empty\n \"\"\"\n Given a DocString with content type\n \"\"\"xml\n <foo>\n <bar />\n </foo>\n \"\"\"\n And a DocString with wrong indentation\n \"\"\"\n wrongly indented line\n \"\"\"\n And a DocString with alternative separator\n ```\n first line\n second line\n ```\n And a DocString with normal separator inside\n ```\n first line\n \"\"\"\n third line\n ```\n And a DocString with alternative separator inside\n \"\"\"\n first line\n ```\n third line\n \"\"\"\n And a DocString with escaped separator inside\n \"\"\"\n first line\n \\\"\\\"\\\"\n third line\n \"\"\"\n And a DocString with an escaped alternative separator inside\n ```\n first line\n \\`\\`\\`\n third line\n ```",
"mediaType": "text/x.cucumber.gherkin+plain",
"uri": "testdata/good/docstrings.feature"
}
Expand Down
6 changes: 6 additions & 0 deletions gherkin/dotnet/testdata/good/docstrings.feature.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@
(41:1)Other:/"""/
(42:1)Other:/third line/
(43:7)DocStringSeparator:"""//
(44:5)StepLine:And /a DocString with an escaped alternative separator inside/
(45:7)DocStringSeparator:```//
(46:1)Other:/first line/
(47:1)Other:/```/
(48:1)Other:/third line/
(49:7)DocStringSeparator:```//
EOF
2 changes: 1 addition & 1 deletion gherkin/go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ PICKLES = $(patsubst testdata/%.feature,acceptance/testdata/%.feature.pickl
SOURCES = $(patsubst testdata/%.feature,acceptance/testdata/%.feature.source.ndjson,$(GOOD_FEATURE_FILES))
ERRORS = $(patsubst testdata/%.feature,acceptance/testdata/%.feature.errors.ndjson,$(BAD_FEATURE_FILES))

.DELETE_ON_ERROR:
#.DELETE_ON_ERROR:

default: .compared

Expand Down
10 changes: 6 additions & 4 deletions gherkin/go/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,11 @@ func (m *matcher) MatchOther(line *Line) (ok bool, token *Token, err error) {
}

func (m *matcher) unescapeDocString(text string) string {
if m.activeDocStringSeparator != "" {
return strings.Replace(text, "\\\"\\\"\\\"", "\"\"\"", -1)
} else {
return text
if m.activeDocStringSeparator == DOCSTRING_SEPARATOR {
return strings.Replace(text, "\\\"\\\"\\\"", DOCSTRING_SEPARATOR, -1)
}
if m.activeDocStringSeparator == DOCSTRING_ALTERNATIVE_SEPARATOR {
return strings.Replace(text, "\\`\\`\\`", DOCSTRING_ALTERNATIVE_SEPARATOR, -1)
}
return text
}
6 changes: 6 additions & 0 deletions gherkin/go/testdata/good/docstrings.feature
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ Feature: DocString variations
\"\"\"
third line
"""
And a DocString with an escaped alternative separator inside
```
first line
\`\`\`
third line
```
19 changes: 18 additions & 1 deletion gherkin/go/testdata/good/docstrings.feature.ast.ndjson
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"children": [
{
"scenario": {
"id": "7",
"id": "8",
"keyword": "Scenario",
"location": {
"column": 3,
Expand Down Expand Up @@ -131,6 +131,23 @@
"line": 38
},
"text": "a DocString with escaped separator inside"
},
{
"docString": {
"content": "first line\n```\nthird line",
"delimiter": "```",
"location": {
"column": 7,
"line": 45
}
},
"id": "7",
"keyword": "And ",
"location": {
"column": 5,
"line": 44
},
"text": "a DocString with an escaped alternative separator inside"
}
]
}
Expand Down