Repository: Behat/Gherkin (php)

Issue:
Newlines in table content are not un-escaped
Per `datatables_with_new_lines.feature` in the gherkin testdata, with a table like:

```
    Given 3 lines of poetry on 5 lines
      |  \nraindrops--\nher last kiss\ngoodbye.\n  |
```

The `\n` characters should be parsed as actual newlines, to give cell content matching:

```
raindrops--
her last kiss
goodbye.

```

However, we currently return these as the raw content, e.g. with explicit `\` `n` characters, rather than newlines.

See #325

Pull request description:
feat: Add support for newlines in table cells in `gherkin-32` mode
Closes #327

Patch:
diff --git a/src/GherkinCompatibilityMode.php b/src/GherkinCompatibilityMode.php
index 6ed5a33..c4a5497 100644
--- a/src/GherkinCompatibilityMode.php
+++ b/src/GherkinCompatibilityMode.php
@@ -32,6 +32,17 @@ enum GherkinCompatibilityMode: string
         };
     }
 
+    /**
+     * @internal
+     */
+    public function shouldSupportNewlineEscapeSequenceInTableCell(): bool
+    {
+        return match ($this) {
+            self::LEGACY => false,
+            default => true,
+        };
+    }
+
     /**
      * @internal
      */
diff --git a/src/Lexer.php b/src/Lexer.php
index 73244f4..4d23f75 100644
--- a/src/Lexer.php
+++ b/src/Lexer.php
@@ -730,7 +730,11 @@ class Lexer
         array_pop($rawColumns);
 
         $token = $this->takeToken('TableRow');
-        $columns = array_map(static fn ($column) => trim(str_replace(['\\|', '\\\\'], ['|', '\\'], $column)), $rawColumns);
+        if ($this->compatibilityMode->shouldSupportNewlineEscapeSequenceInTableCell()) {
+            $columns = array_map(static fn ($column) => trim(str_replace(['\\|', '\n', '\\\\'], ['|', "\n", '\\'], $column), ' '), $rawColumns);
+        } else {
+            $columns = array_map(static fn ($column) => trim(str_replace(['\\|', '\\\\'], ['|', '\\'], $column)), $rawColumns);
+        }
         $token['columns'] = $columns;
 
         $this->consumeLine();


Test patch:
diff --git a/tests/Cucumber/CompatibilityTest.php b/tests/Cucumber/CompatibilityTest.php
index c181944..febeb0b 100644
--- a/tests/Cucumber/CompatibilityTest.php
+++ b/tests/Cucumber/CompatibilityTest.php
@@ -59,7 +59,6 @@ class CompatibilityTest extends TestCase
         'gherkin-32' => [
             'complex_background.feature' => 'Rule keyword not supported',
             'docstrings.feature' => 'Escaped delimiters in docstrings are not unescaped',
-            'datatables_with_new_lines.feature' => 'Escaped newlines in table cells are not unescaped',
             'escaped_pipes.feature' => 'Escaped newlines in table cells are not unescaped',
             'rule.feature' => 'Rule keyword not supported',
             'rule_with_tag.feature' => 'Rule keyword not supported',