Skip to content

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

@hobdell-SAP

Description

@hobdell-SAP

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
[email protected] /Users/xxxx/projects/obfuscated-package
└── [email protected]
$ 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...

Metadata

Metadata

Assignees

Labels

🐛 bugDefect / Bug✅ acceptedThe core team has agreed that it is a good idea to fix this

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions