diff --git a/lib/cucumber/rb_support/rb_transform.rb b/lib/cucumber/rb_support/rb_transform.rb index b9a93435b1..4f8bde1612 100644 --- a/lib/cucumber/rb_support/rb_transform.rb +++ b/lib/cucumber/rb_support/rb_transform.rb @@ -39,7 +39,9 @@ def to_s private def convert_captures(regexp_source) - regexp_source.gsub(/(\()(?!\?:)/,'(?:') + regexp_source + .gsub(/(\()(?!\?[<:=!])/,'(?:') + .gsub(/(\(\?<)(?![=!])/,'(?:<') end def strip_captures(regexp_source) diff --git a/spec/cucumber/rb_support/rb_transform_spec.rb b/spec/cucumber/rb_support/rb_transform_spec.rb index 0293066e51..ec6573b8c2 100644 --- a/spec/cucumber/rb_support/rb_transform_spec.rb +++ b/spec/cucumber/rb_support/rb_transform_spec.rb @@ -9,6 +9,26 @@ def transform(regexp) end describe "#to_s" do + it "do not touch positive lookahead captures" do + expect(transform(/^xy(?=z)/).to_s).to eq "xy(?=z)" + end + + it "do not touch negative lookahead captures" do + expect(transform(/^xy(?!z)/).to_s).to eq "xy(?!z)" + end + + it "do not touch positive lookbehind captures" do + expect(transform(/^xy(?<=z)/).to_s).to eq "xy(?<=z)" + end + + it "do not touch negative lookbehind captures" do + expect(transform(/^xy(?xyz)/).to_s).to eq "(?:xyz)" + end + it "converts captures groups to non-capture groups" do expect(transform(/(a|b)bc/).to_s).to eq "(?:a|b)bc" end