Escaping nightmare in Gherkin Examples block

56 views
Skip to first unread message

Paolo Ambrosio

unread,
Aug 15, 2016, 1:54:04 AM8/15/16
to cu...@googlegroups.com
Hi,

Yesterday I went mad trying to find out how escaping is supposed to
work in Gherkin Examples blocks... and still haven't found it.

The attached file cucumber.out contains the output of a run of
Cucumber (-Ruby 2.0.0 or 2.4.0 gave the same result) on
escaping.feature with a step definition that simply prints what has
been passed. This is an estract:

Examples:
| a |
| \\+ |
| \\+ |
| \\\\+ | \+
| \\\\+ | \+
| \\\\\\+ | \
| \\\\\\+ | \
| \\\\\\\\+ | \\+
| \\\\\\\\+ | \\+

The output normalises the "a" column so that \+ becomes \\+ (not sure
why that happens but it's not important). What puzzles me is the +
even disappearing at some point, as well as the completely different
behaviour I get when using "." instead of "+":

Examples:
| a |
| \\. | \.
| \\. | \.
| \\\\. | \.
| \\\\. | \.
| \\\\\\. | \\.
| \\\\\\. | \\.
| \\\\\\\\. | \\.
| \\\\\\\\. | \\.

Can anyone explain to me what the rule is? Is this a bug or intended
behaviour? Haven't tried with other Cucumber implementations yet.

Cheers,
Paolo
cucumber.out
escaping.feature

Björn Rasmusson

unread,
Aug 15, 2016, 12:25:30 PM8/15/16
to Cukes
Hi,

The intended behaviour of the Gherkin v4 parser (which is used in Cucumber-Ruby v2.4.0) is specified by the escaped_pipes.feature, that is "The \-character will be considered as an escape in table cell if and only if it is followed by a '|'-character, a '\'-character or an 'n'."

Regards
Björn

Paolo Ambrosio

unread,
Aug 15, 2016, 3:52:21 PM8/15/16
to cu...@googlegroups.com
Hi Björn,

Thanks for your reply. What you described is the behaviour I was
expecting so I tried with Java and I get the expected result.

At this point I might be doing something wrong with Ruby. This is my
step definition in Ruby:

Given(/^'([^']*)'$/) do |x|
puts x
end

This is in Java:

@Given("^'([^']*)'$")
public void printEscaping(String e) {
System.out.println(e);
}

They give completely different results for the same feature file.

Thanks,
Paolo

>> Is this a bug or intended
>> behaviour? Haven't tried with other Cucumber implementations yet.
>>
>> Cheers,
>> Paolo
>
> --
> Posting rules: http://cukes.info/posting-rules.html
> ---
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cukes+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

aslak hellesoy

unread,
Aug 16, 2016, 8:03:05 AM8/16/16
to cu...@googlegroups.com
Once Java uses Gherkin 4 it should be consistent. Björn has a pending PR. 

Aslak

Paolo Ambrosio

unread,
Aug 16, 2016, 9:55:34 AM8/16/16
to cu...@googlegroups.com
Hi Aslak,

In my first email I specified that Cucumber-Ruby 2.0.0 (Gherkin
2.12.2) and 2.4.0 (Gherkin 4.0.0) show the same behaviour.

I still don't get how with the rules written by Björn can interpret
"\\\\\\+" as "\" in the Ruby version (Gherkin 2 or 4), but "\\\+" in
Java as I would expect.

For example how should "\\\\\\\\\\\\" be interpreted?

Paolo

aslak hellesoy

unread,
Aug 16, 2016, 10:07:25 AM8/16/16
to Cucumber Users
That should become \\\\\\

You can verify that this is the case if you add a row to https://github.com/cucumber/gherkin/blob/master/testdata/good/escaped_pipes.feature, then run make from e.g. the ruby directory.

Aslak
 
Paolo

> Aslak
>>
>>
>> Thanks,
>> Paolo
>>
>> >> Is this a bug or intended
>> >> behaviour? Haven't tried with other Cucumber implementations yet.
>> >>
>> >> Cheers,
>> >> Paolo
>> >
>> > --
>> > Posting rules: http://cukes.info/posting-rules.html
>> > ---
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Cukes" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an

>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> Posting rules: http://cukes.info/posting-rules.html
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Cukes" group.
>> To unsubscribe from this group and stop receiving emails from it, send an

>> For more options, visit https://groups.google.com/d/optout.
>
> --
> Posting rules: http://cukes.info/posting-rules.html
> ---
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To unsubscribe from this group and stop receiving emails from it, send an

> For more options, visit https://groups.google.com/d/optout.

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe@googlegroups.com.

Paolo Ambrosio

unread,
Aug 16, 2016, 5:37:49 PM8/16/16
to cu...@googlegroups.com
On Tue, Aug 16, 2016 at 3:07 PM, aslak hellesoy
That is exactly what I was expecting and what I get in Java, but
instead in Ruby I got \\\

I've tried modifying that feature in Gherkin 4 and it is definitely
doing the right thing, unlike Cucumber-Ruby.

I Would expect these two scenarios to be equivalent:

Scenario:
Given '\\\+'
And '\\\\\\'

Scenario Outline:
Given '<a>'
And '<b>'

Examples:
| a | b |
| \\\\\\+ | \\\\\\\\\\\\ |

But they are not. They produce different output with this step definition:

Given(/^'([^']*)'$/) do |x|
puts x
end


> You can verify that this is the case if you add a row to
> https://github.com/cucumber/gherkin/blob/master/testdata/good/escaped_pipes.feature,
> then run make from e.g. the ruby directory.
>
> Aslak
>
>>
>> Paolo
>>
>> > Aslak
>> >>
>> >>
>> >> Thanks,
>> >> Paolo
>> >>
>> >> >> Is this a bug or intended
>> >> >> behaviour? Haven't tried with other Cucumber implementations yet.
>> >> >>
>> >> >> Cheers,
>> >> >> Paolo
>> >> >
>> >> > --
>> >> > Posting rules: http://cukes.info/posting-rules.html
>> >> > ---
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> > "Cukes" group.
>> >> > To unsubscribe from this group and stop receiving emails from it,
>> >> > send
>> >> > an
>> >> > email to cukes+un...@googlegroups.com.
>> >> > For more options, visit https://groups.google.com/d/optout.
>> >>
>> >> --
>> >> Posting rules: http://cukes.info/posting-rules.html
>> >> ---
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "Cukes" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> >> an
>> >> email to cukes+un...@googlegroups.com.
>> >> For more options, visit https://groups.google.com/d/optout.
>> >
>> > --
>> > Posting rules: http://cukes.info/posting-rules.html
>> > ---
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Cukes" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to cukes+un...@googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> Posting rules: http://cukes.info/posting-rules.html
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Cukes" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to cukes+un...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> Posting rules: http://cukes.info/posting-rules.html
> ---
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cukes+un...@googlegroups.com.

aslak hellesoy

unread,
Aug 16, 2016, 5:57:12 PM8/16/16
to Cucumber Users
Hmm. Cucumber-Ruby 2.4.0 is using Gherkin 4.0

Could it be that Cucumber-Ruby is doing something weird?
 

>> >> > For more options, visit https://groups.google.com/d/optout.
>> >>
>> >> --
>> >> Posting rules: http://cukes.info/posting-rules.html
>> >> ---
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "Cukes" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> >> an

>> >> For more options, visit https://groups.google.com/d/optout.
>> >
>> > --
>> > Posting rules: http://cukes.info/posting-rules.html
>> > ---
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Cukes" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an

>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> Posting rules: http://cukes.info/posting-rules.html
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Cukes" group.
>> To unsubscribe from this group and stop receiving emails from it, send an

>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> Posting rules: http://cukes.info/posting-rules.html
> ---
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To unsubscribe from this group and stop receiving emails from it, send an

> For more options, visit https://groups.google.com/d/optout.

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe@googlegroups.com.

Paolo Ambrosio

unread,
Aug 16, 2016, 6:16:29 PM8/16/16
to cu...@googlegroups.com
On Tue, Aug 16, 2016 at 10:56 PM, aslak hellesoy
I think I found a better example to reproduce the error. The following
scenario fails on the second step:


Feature: Escaping

Scenario Outline:
* '<a>' should equal '|'
* '<b>' should equal '\\\+'
* '<c>' should equal '\\\\\\'

Examples:
| a | b | c |
| \| | \\\\\\+ | \\\\\\\\\\\\ |


Given(/^'([^']*)' should equal '([^']*)'$/) do |x,y|
x.should == y
end


Should I raise the issue on the Cucumber-Ruby repo?
>> >> >> > email to cukes+un...@googlegroups.com.
>> >> >> > For more options, visit https://groups.google.com/d/optout.
>> >> >>
>> >> >> --
>> >> >> Posting rules: http://cukes.info/posting-rules.html
>> >> >> ---
>> >> >> You received this message because you are subscribed to the Google
>> >> >> Groups
>> >> >> "Cukes" group.
>> >> >> To unsubscribe from this group and stop receiving emails from it,
>> >> >> send
>> >> >> an
>> >> >> email to cukes+un...@googlegroups.com.
>> >> >> For more options, visit https://groups.google.com/d/optout.
>> >> >
>> >> > --
>> >> > Posting rules: http://cukes.info/posting-rules.html
>> >> > ---
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> > "Cukes" group.
>> >> > To unsubscribe from this group and stop receiving emails from it,
>> >> > send
>> >> > an
>> >> > email to cukes+un...@googlegroups.com.
>> >> > For more options, visit https://groups.google.com/d/optout.
>> >>
>> >> --
>> >> Posting rules: http://cukes.info/posting-rules.html
>> >> ---
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "Cukes" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> >> an
>> >> email to cukes+un...@googlegroups.com.
>> >> For more options, visit https://groups.google.com/d/optout.
>> >
>> >
>> > --
>> > Posting rules: http://cukes.info/posting-rules.html
>> > ---
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Cukes" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to cukes+un...@googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> Posting rules: http://cukes.info/posting-rules.html
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Cukes" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to cukes+un...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> Posting rules: http://cukes.info/posting-rules.html
> ---
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cukes+un...@googlegroups.com.

aslak hellesoy

unread,
Aug 16, 2016, 6:32:40 PM8/16/16
to Cucumber Users
What's the actual result?
 

Should I raise the issue on the Cucumber-Ruby repo?


Try it and see what they say. We'll get to the bottom of it.
 

>> >> >> > For more options, visit https://groups.google.com/d/optout.
>> >> >>
>> >> >> --
>> >> >> Posting rules: http://cukes.info/posting-rules.html
>> >> >> ---
>> >> >> You received this message because you are subscribed to the Google
>> >> >> Groups
>> >> >> "Cukes" group.
>> >> >> To unsubscribe from this group and stop receiving emails from it,
>> >> >> send
>> >> >> an

>> >> >> For more options, visit https://groups.google.com/d/optout.
>> >> >
>> >> > --
>> >> > Posting rules: http://cukes.info/posting-rules.html
>> >> > ---
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> > "Cukes" group.
>> >> > To unsubscribe from this group and stop receiving emails from it,
>> >> > send
>> >> > an

>> >> > For more options, visit https://groups.google.com/d/optout.
>> >>
>> >> --
>> >> Posting rules: http://cukes.info/posting-rules.html
>> >> ---
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "Cukes" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> >> an

>> >> For more options, visit https://groups.google.com/d/optout.
>> >
>> >
>> > --
>> > Posting rules: http://cukes.info/posting-rules.html
>> > ---
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Cukes" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an

>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> Posting rules: http://cukes.info/posting-rules.html
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Cukes" group.
>> To unsubscribe from this group and stop receiving emails from it, send an

>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> Posting rules: http://cukes.info/posting-rules.html
> ---
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To unsubscribe from this group and stop receiving emails from it, send an

> For more options, visit https://groups.google.com/d/optout.

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe@googlegroups.com.

Paolo Ambrosio

unread,
Aug 17, 2016, 2:08:49 AM8/17/16
to cu...@googlegroups.com
On Tue, Aug 16, 2016 at 11:32 PM, aslak hellesoy
expected: "\\\\\\+"
got: "\\" (using ==) (RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/escaping.rb:6:in `/^'([^']*)' should
equal '([^']*)'$/'
features/escaping.feature:10:in `* '\' should equal '\\\+''
features/escaping.feature:5:in `* '<b>' should equal '\\\+''

>> Should I raise the issue on the Cucumber-Ruby repo?
>
> Try it and see what they say. We'll get to the bottom of it.

Opened a new issue: https://github.com/cucumber/cucumber-ruby/issues/1006

Discussing it here first hopefully produced a better bug report :-)

Thanks,
Paolo
>> >> >> >> > email to cukes+un...@googlegroups.com.
>> >> >> >> > For more options, visit https://groups.google.com/d/optout.
>> >> >> >>
>> >> >> >> --
>> >> >> >> Posting rules: http://cukes.info/posting-rules.html
>> >> >> >> ---
>> >> >> >> You received this message because you are subscribed to the
>> >> >> >> Google
>> >> >> >> Groups
>> >> >> >> "Cukes" group.
>> >> >> >> To unsubscribe from this group and stop receiving emails from it,
>> >> >> >> send
>> >> >> >> an
>> >> >> >> email to cukes+un...@googlegroups.com.
>> >> >> >> For more options, visit https://groups.google.com/d/optout.
>> >> >> >
>> >> >> > --
>> >> >> > Posting rules: http://cukes.info/posting-rules.html
>> >> >> > ---
>> >> >> > You received this message because you are subscribed to the Google
>> >> >> > Groups
>> >> >> > "Cukes" group.
>> >> >> > To unsubscribe from this group and stop receiving emails from it,
>> >> >> > send
>> >> >> > an
>> >> >> > email to cukes+un...@googlegroups.com.
>> >> >> > For more options, visit https://groups.google.com/d/optout.
>> >> >>
>> >> >> --
>> >> >> Posting rules: http://cukes.info/posting-rules.html
>> >> >> ---
>> >> >> You received this message because you are subscribed to the Google
>> >> >> Groups
>> >> >> "Cukes" group.
>> >> >> To unsubscribe from this group and stop receiving emails from it,
>> >> >> send
>> >> >> an
>> >> >> email to cukes+un...@googlegroups.com.
>> >> >> For more options, visit https://groups.google.com/d/optout.
>> >> >
>> >> >
>> >> > --
>> >> > Posting rules: http://cukes.info/posting-rules.html
>> >> > ---
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups
>> >> > "Cukes" group.
>> >> > To unsubscribe from this group and stop receiving emails from it,
>> >> > send
>> >> > an
>> >> > email to cukes+un...@googlegroups.com.
>> >> > For more options, visit https://groups.google.com/d/optout.
>> >>
>> >> --
>> >> Posting rules: http://cukes.info/posting-rules.html
>> >> ---
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "Cukes" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> >> an
>> >> email to cukes+un...@googlegroups.com.
>> >> For more options, visit https://groups.google.com/d/optout.
>> >
>> >
>> > --
>> > Posting rules: http://cukes.info/posting-rules.html
>> > ---
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Cukes" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> > an
>> > email to cukes+un...@googlegroups.com.
>> > For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> Posting rules: http://cukes.info/posting-rules.html
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Cukes" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to cukes+un...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> Posting rules: http://cukes.info/posting-rules.html
> ---
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cukes+un...@googlegroups.com.

aslak hellesoy

unread,
Aug 17, 2016, 2:15:27 AM8/17/16
to cu...@googlegroups.com
That's a model bug report!
Reply all
Reply to author
Forward
0 new messages