Skip to content

Support escaped pipe (\|) in Gherkin table cells#81

Merged
mchaloupka merged 3 commits intofsprojects:masterfrom
deyanp:fix/escape-pipe-in-table-cells
Mar 25, 2026
Merged

Support escaped pipe (\|) in Gherkin table cells#81
mchaloupka merged 3 commits intofsprojects:masterfrom
deyanp:fix/escape-pipe-in-table-cells

Conversation

@deyanp
Copy link
Copy Markdown
Contributor

@deyanp deyanp commented Mar 22, 2026

Summary

  • Add support for \| escape sequences in Gherkin table cells, aligning TickSpec with the Gherkin specification and other frameworks (Cucumber, SpecFlow)
  • The TableRowLine parser now replaces \| with a placeholder before splitting on |, then restores literal | in the resulting cell values
  • Existing behavior is fully preserved — tables without \| work exactly as before

Motivation

Currently, it's impossible to include a literal pipe character (|) in a Gherkin table cell value, since | is always treated as a column delimiter. The Gherkin spec defines \| as the standard escape for this, and other BDD frameworks support it. This is useful when testing values that naturally contain pipes (e.g., KQL queries, shell commands, regex patterns).

Test plan

  • Added EscapedPipe.feature with scenarios covering: no escapes (backward compat), single escaped pipe, leading/trailing pipes, multiple escaped pipes in one cell, and step tables with escaped pipes
  • Added EscapedPipe_ParseLines test verifying line-level parsing produces correct TableRow values with literal |
  • Added EscapedPipe_ParseFeature test verifying full feature parsing resolves escaped pipes in both Scenario Outline parameters and step table cells
  • Run existing test suite to confirm no regressions

🤖 Generated with Claude Code

deyanp and others added 2 commits March 23, 2026 00:25
The Gherkin specification defines \| as an escape sequence for literal
pipe characters within table cells. TickSpec previously split table rows
on all | characters without handling escapes, making it impossible to
include pipe characters in table data.

Replace \| with a placeholder before splitting, then restore the literal
| in the resulting cell values. This aligns TickSpec with the behavior
of Cucumber, SpecFlow, and other Gherkin-based frameworks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Scenarios.[2] is the third Examples row ("|leading"), not "before|after".
Fixed indices: 1 for "before|after", 4 for "a|b|c".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mchaloupka
Copy link
Copy Markdown
Collaborator

Would you mind adding support for the full escaping logic as described?
https://cucumber.io/docs/gherkin/reference/#table-cell-escapin

If you want to use a newline character in a table cell, you can write this as \n. If you need a | as part of the cell, you can escape it as |. And finally, if you need a , you can escape that with \.

E.g. the code currently rewrites \\| into \| which is incorrect. It should be just \ and then split.

Implement the complete escape logic per the Cucumber spec:
- \\ → literal backslash
- \| → literal pipe (not a cell delimiter)
- \n → newline character

Fix \\| being incorrectly treated as escaped pipe instead of
escaped backslash followed by a cell delimiter.
@mchaloupka mchaloupka merged commit 8e1de3b into fsprojects:master Mar 25, 2026
2 checks passed
@mchaloupka
Copy link
Copy Markdown
Collaborator

Thanks for doing this work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants