gauge icon indicating copy to clipboard operation
gauge copied to clipboard

Formatting a spec with escape character is removing the escape character

Open sswaroopgupta opened this issue 8 years ago • 5 comments

Formatting spec with escape character is removing the escape character.

Steps to reproduce

  1. Create a spec and add the following contents.
Formatting a spec with escape character
===============================
* Create a scenario "Sample scenario" with the following steps with implementation 
     |step text|implementation|
     |---------|--------------|
     |A step |"\"content\""|
  1. Run gauge format specs.

Expected Behavior

Gauge should simply format the spec file without changing any contents.

Actual Behavior

Gauge is removing the escape chars. The text "\"content\"" is getting formatted to ""content"". The double backslash (\\) are gone.

Gauge version

$ gauge -v
Gauge version: 0.4.0

Plugins
-------
html-report (2.1.0)
java (0.3.4)

sswaroopgupta avatar Apr 05 '16 04:04 sswaroopgupta

Issue replicable.

Gauge Version

Gauge version: 0.9.1

Plugins
-------
csharp (0.10.1)
html-report (4.0.1)
java (0.6.5)
js (2.0.0)
ruby (0.4.1)
xml-report (0.2.0)

sriv avatar Aug 14 '17 12:08 sriv

Investigation: This issue is occuring because we are handling escape sequences in a special way in parser/processor.go, processTable function. This is because when we read from the file where the text is "\"content\"" into a string, it is read should internally be \"\\\"content\\\"\" but we are dropping the \\ character so it is actually becoming \"\"content\"\" so there is no way of knowing which one was escaped and which one was not. Similar problem will also occur for the following example "a\tb" which will become "atb" since \\ would be removed leaving behind the t

Parser needs to have context when to escape the string and when not to since we are using the same parser for format as well as run

riju91 avatar Dec 19 '17 05:12 riju91

Did this bug ever get fixed before the issue was closed? I'm trying to do something like this:

* Given a multiline comment

|id|comment                  |
|--|-------------------------|
|1 |First line \n second line|

But every time I save/format the file it strips the backslash out. I tried putting a double-backslash - the first save & format removes the first backslash, and then the second time I save it removes the second one. I also tried wrapping the whole string in quotes but that didn't help either.

For now what I've done is use a forward slash instead, and then in the step implementation I do comment.replace('/n', '\n'), but it's a bit of a hack...

camjackson avatar Oct 27 '20 00:10 camjackson

Can confirm that this is an issue. Reopening.

thanks for bringing this to our attention, @camjackson

sriv avatar Oct 28 '20 03:10 sriv

Hello. Issue with "/n" described by @camjackson is still present on version: Gauge version: 1.4.3 Commit Hash: f98dd40

Example:

| Characteristic | Customer                                                                                                                    |         
| Client Type     | Account holder: Professional \n Discussion partner: Professional, acting as retail client |

admbcko avatar Jun 14 '23 12:06 admbcko