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

Parsing error for step definition written in Java #111

Open
DanielSCy opened this issue Oct 19, 2022 · 1 comment
Open

Parsing error for step definition written in Java #111

DanielSCy opened this issue Oct 19, 2022 · 1 comment
Labels
🐛 bug Defect / Bug java

Comments

@DanielSCy
Copy link

DanielSCy commented Oct 19, 2022

👓 What did you see?

I have below step defined in my steps file:

@Given("I have a menu item with name \"([^\"]+)\" and price (\\d+)")

The \ before " is required by Java but the language server should only see ". Also, when I run the tests everything is well, so it's not an issue with the definition of the step or the feature file. However, the language server gives the below exception and the step is not recognized in the feature file:

[Error - 5:03:40 PM] * Step Definition errors: Error: This Cucumber Expression has a problem at column 31:

I have a menu item with name \"([^\"]+)\" and price (\d+)
                              ^
Only the characters '{', '}', '(', ')', '\', '/' and whitespace can be escaped.
If you did mean to use an '\' you can use '\\' to escape it
	at RT (c:\Users\dstanciu\.vscode\extensions\cucumberopen.cucumber-official-1.5.1\out\extension.js:67:79988)
	at d (c:\Users\dstanciu\.vscode\extensions\cucumberopen.cucumber-official-1.5.1\out\extension.js:84:501)
	at c:\Users\dstanciu\.vscode\extensions\cucumberopen.cucumber-official-1.5.1\out\extension.js:84:702
	at Array.forEach (<anonymous>)
	at ac.tokenize (c:\Users\dstanciu\.vscode\extensions\cucumberopen.cucumber-official-1.5.1\out\extension.js:84:636)
	at uc.parse (c:\Users\dstanciu\.vscode\extensions\cucumberopen.cucumber-official-1.5.1\out\extension.js:84:2357)
	at new ji (c:\Users\dstanciu\.vscode\extensions\cucumberopen.cucumber-official-1.5.1\out\extension.js:84:5199)
	at ga.createExpression (c:\Users\dstanciu\.vscode\extensions\cucumberopen.cucumber-official-1.5.1\out\extension.js:84:11717)
	at c:\Users\dstanciu\.vscode\extensions\cucumberopen.cucumber-official-1.5.1\out\extension.js:427:748
	at $f.eachStepDefinitionExpression (c:\Users\dstanciu\.vscode\extensions\cucumberopen.cucumber-official-1.5.1\out\extension.js:424:1769)
	at Wf.build (c:\Users\dstanciu\.vscode\extensions\cucumberopen.cucumber-official-1.5.1\out\extension.js:427:695)
	at Sc.<anonymous> (c:\Users\dstanciu\.vscode\extensions\cucumberopen.cucumber-official-1.5.1\out\extension.js:433:19176)
	at Generator.next (<anonymous>)
	at u (c:\Users\dstanciu\.vscode\extensions\cucumberopen.cucumber-official-1.5.1\out\extension.js:433:11215)
	at process.processTicksAndRejections (node:internal/process/task_queues:96:5)

✅ What did you expect to see?

The step definition would be parsed without error.

📦 Which tool/library version are you using?

I am running VSCode with cucumber extension 1,5,1 as seen also in the stack trace.

🔬 How could we reproduce it?

Steps to reproduce the behavior:

  1. Install VSCode with Cucumber extension version '1.5.1'
  2. Create a Java based Cucumber project, with one feature and one step definition. Use " in the step definition to allow " characters
  3. Create a features file using that step.
  4. The step is not recognized and the 'Cucumber Server Language' output window shows the exception mentioned above.

@aslakhellesoy aslakhellesoy transferred this issue from cucumber/language-server Oct 31, 2022
@aslakhellesoy
Copy link
Contributor

Hi @DanielSCy thanks for reporting this. It sounds like we need to handle escapes better in unescapeString:

function unescapeString(s: string): string {

Currently it's only escaping \\ back to \, but it should handle all Java String escapes.
A test for this should be added to https://github.com/cucumber/language-service/blob/main/test/language/javaLanguage.test.ts

We might take inspiration from https://github.com/iamakulov/unescape-js (I don't want to depend on the library which is unlikely to be maintained).

There are also some more details about this in this SO post

Would you be able to help with a pull request with this @DanielSCy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug java
Projects
None yet
Development

No branches or pull requests

3 participants