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

Generated snippets with special characters are not correctly escaped. #1324

Closed
hobdell-SAP opened this issue Jun 8, 2020 · 2 comments · Fixed by #1995
Closed

Generated snippets with special characters are not correctly escaped. #1324

hobdell-SAP opened this issue Jun 8, 2020 · 2 comments · Fixed by #1995
Assignees
Labels
🐛 bug Defect / Bug ✅ accepted The core team has agreed that it is a good idea to fix this

Comments

@hobdell-SAP
Copy link

hobdell-SAP commented Jun 8, 2020

Prerequisite Due Diligence

  • I could not find related issues about escaping special characters in the error output.
  • I'm only parsing features and step defs (no tests are yet implemented), so definitely cucumber-js.
  • This is a bug report. Version Info and steps to reproduce follow.

Version Info

$ node -v
v12.10.0
$ npm ls cucumber
obfuscated-package@1.0.0 /Users/xxxx/projects/obfuscated-package
└── cucumber@6.0.5
$ set | grep OSTYPE
OSTYPE=darwin19.3.0
(macOS Catalina 10.15.5)
$ bash --version
GNU bash, version 5.0.16(1)-release (x86_64-apple-darwin19.3.0)
(installed with Homebrew)

Steps to reproduce

I'm going from BDD to code. The first step when adding new features is to identify the step defs. I do this by running cucumber, then script-processing the output to extract the missing fragments into stepdef files.

A typical missing step def results in an error like this:

? When the user (with permissions) executes the action
        Undefined. Implement with the following snippet:

          When('the user \(with permissions) executes the action', function () {
            // Write code here that turns the phrase above into concrete actions
            return 'pending';
          });

After I run my script to extract the snippets, I have a stepdef file with the snippet contents:

const assert = require('assert');
const { Given, When, Then } = require('cucumber');
          When('the user \(with permissions) executes the action', function () {
            // Write code here that turns the phrase above into concrete actions
            return 'pending';
          });

But running cucumber again still reports the Undefined stepdef.

## Workaround
My script replaces the '\' with '\\', but the suggestion output should be correct, and not open to interpretation.

I tracked it down to https://github.com/cucumber/cucumber-js/tree/master/src/formatter/step_definition_snippet_builder before getting lost in the multi-project structure...

@hobdell-SAP
Copy link
Author

I have edited the description twice to format the backslashes correctly. It seems that escaping of backslashes isn't just a cucumber issue! :)

@aslakhellesoy aslakhellesoy added the 🐛 bug Defect / Bug label Feb 2, 2021
@davidjgoss davidjgoss self-assigned this Apr 11, 2022
@davidjgoss davidjgoss added the ✅ accepted The core team has agreed that it is a good idea to fix this label Apr 11, 2022
@davidjgoss
Copy link
Contributor

This has now been released in v8.1.0 on npm

https://www.npmjs.com/package/@cucumber/cucumber

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug ✅ accepted The core team has agreed that it is a good idea to fix this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants