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

Issue with parsing of constants in Examples since 4.10.0 strips slashes #268

Closed
markdavidsonEE opened this issue Oct 21, 2024 · 2 comments
Closed

Comments

@markdavidsonEE
Copy link

We have Examples where we make use of constant

    Examples:
      | typeId                                                                           |
      | {{constant("Test\\Path\\Class::ABC") }}      |

in 4.9.0 this works as expected.

However with 4.10.0 we see the following

    Examples:
      | typeid                                                                    |
      | {{constant("Test\\Path\\Class::ABC") }} |
        Failed step: When I create a new campaign with payload:
        Constant "TestPathClass::ABC" is undefined in "__string_template__e98fd17d5ab7ca2d8fd75aea159728c6" at line 8. (Twig\Error\RuntimeError)

--- Failed scenarios:

So slashes are getting stripped, if we change the \\ to a \\\ it works.

Can anyone confirm if this is an intentional change?

@acoulton
Copy link
Contributor

It looks to me like this was intentional, albeit not quite explicit, to maintain compatibility with the main cucumber/gherkin parser:

  • The change here was 5a0836d which was to get the build green again on the test that compares behat/gherkin's parsing with the official cucumber test data
  • That test had been failing since Cucumber update 24.1.0 #255 was merged to update us to gherkin 24.1.0 - because the update itself comes from github actions it doesn't run CI - we'll need to look at how to improve that in future
  • And the change in gherkin 24.1.0 was the introduction of this new testcase to Fix gherkin-python for compiling example values with trailing backslash which looks like it came from this PR Fix gherkin-python for compiling example values with trailing backslash cucumber/common#2048 before they split cucumber out from monorepos.

The cucumber gherkin reference docs say:

Table Cell Escaping

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 \.

That seems to have been the case since at least 2021 and probably before that (the link to the spec in that issue is now broken and I think I'm far enough down the rabbit hole!).

So as far as I can see, behat/gherkin has historically not been parsing the \\ in your tables correctly, and that has been fixed in v4.10.0.

Although I appreciate it will be frustrating to have to update your examples on a point release, I think that (using \\\\ to escape a literal \\) is the correct solution.

@acoulton acoulton closed this as not planned Won't fix, can't repro, duplicate, stale Oct 22, 2024
@markdavidsonEE
Copy link
Author

Thanks very much for the clarification @acoulton, really appreciated.

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

No branches or pull requests

2 participants