cucumber-expressions 6.0.0 → 6.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4e80f6b342fd980a7e30ed217e54f83d5ee4da8198e93487470daff410e4959
4
- data.tar.gz: 9cb0efc96dfc3f26257ac35998bdce354470543ccafdb604e227645fb6f5dd75
3
+ metadata.gz: a9d12cb9c8cd02a9bd908fd7a7f8a4fc7923bafb4b5aa0b4ef6339cb74d634dd
4
+ data.tar.gz: ae0fe8368985342ea0395a1077cab630c4c699ebd65e4c392d69d577fdbf3cd6
5
5
  SHA512:
6
- metadata.gz: 844a25bb968e193a071b4bdfef1a79cc9bd3da3f5211c75adeef363b74ba3e34f7b6cbe578c06fbaf7e6d8f118eae33be2acdca0af5ecd70c8c77c42aac78252
7
- data.tar.gz: e9359ff92fccbc88eb457bec080607397d723d6c488ee4ce87053b360e43268d8a5b3bd4523c3415e76ac8c1b79965db9aff7d4ae6ddb486f3acf02e08e32c7c
6
+ metadata.gz: baacf4121341d24159301ac93259656f4ca28710c6bd63a4dbbc946e7476003b85aca70f11760130d626a6dccf81fcc32e10645aac27e347f040d4897457d3f6
7
+ data.tar.gz: 2da1c94551f4d7d2de12360f437d080364bea94805d7eeb5bdcef2af09b03d59c9471bdf3c12c77b3d8a59a419313de66bb18c47541dd24299906aa0546a2233
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'cucumber-expressions'
4
- s.version = '6.0.0'
4
+ s.version = '6.0.1'
5
5
  s.authors = ["Aslak Hellesøy"]
6
6
  s.description = 'Cucumber Expressions - a simpler alternative to Regular Expressions'
7
7
  s.summary = "cucumber-expressions-#{s.version}"
@@ -80,6 +80,7 @@ module Cucumber
80
80
  "\\{#{$2}\\}"
81
81
  else
82
82
  type_name = $2
83
+ ParameterType.check_parameter_type_name(type_name)
83
84
  parameter_type = parameter_type_registry.lookup_by_type_name(type_name)
84
85
  raise UndefinedParameterTypeError.new(type_name) if parameter_type.nil?
85
86
  @parameter_types.push(parameter_type)
@@ -3,8 +3,20 @@ require 'cucumber/cucumber_expressions/errors'
3
3
  module Cucumber
4
4
  module CucumberExpressions
5
5
  class ParameterType
6
+ ILLEGAL_PARAMETER_NAME_PATTERN = /([\[\]()$.|?*+])/
7
+ UNESCAPE_PATTERN = /(\\([\[$.|?*+\]]))/
8
+
6
9
  attr_reader :name, :type, :regexps
7
10
 
11
+ def self.check_parameter_type_name(type_name)
12
+ unescaped_type_name = type_name.gsub(UNESCAPE_PATTERN) do
13
+ $2
14
+ end
15
+ if ILLEGAL_PARAMETER_NAME_PATTERN =~ unescaped_type_name
16
+ raise CucumberExpressionError.new("Illegal character '#{$1}' in parameter name {#{unescaped_type_name}}")
17
+ end
18
+ end
19
+
8
20
  def prefer_for_regexp_match?
9
21
  @prefer_for_regexp_match
10
22
  end
@@ -23,19 +35,19 @@ module Cucumber
23
35
  # @param prefer_for_regexp_match true if this should be preferred over similar types
24
36
  #
25
37
  def initialize(name, regexp, type, transformer, use_for_snippets, prefer_for_regexp_match)
26
- raise "name can't be nil" if name.nil?
27
38
  raise "regexp can't be nil" if regexp.nil?
28
39
  raise "type can't be nil" if type.nil?
29
40
  raise "transformer can't be nil" if transformer.nil?
30
41
  raise "use_for_snippets can't be nil" if use_for_snippets.nil?
31
42
  raise "prefer_for_regexp_match can't be nil" if prefer_for_regexp_match.nil?
32
43
 
44
+ self.class.check_parameter_type_name(name) unless name.nil?
33
45
  @name, @type, @transformer, @use_for_snippets, @prefer_for_regexp_match = name, type, transformer, use_for_snippets, prefer_for_regexp_match
34
46
  @regexps = string_array(regexp)
35
47
  end
36
48
 
37
49
  def transform(self_obj, group_values)
38
- group_values.empty? ? nil : self_obj.instance_exec(*group_values, &@transformer)
50
+ self_obj.instance_exec(*group_values, &@transformer)
39
51
  end
40
52
 
41
53
  def <=>(other)
@@ -14,10 +14,10 @@ module Cucumber
14
14
  @parameter_type_by_name = {}
15
15
  @parameter_types_by_regexp = Hash.new {|hash, regexp| hash[regexp] = []}
16
16
 
17
- define_parameter_type(ParameterType.new('int', INTEGER_REGEXPS, Integer, lambda {|s| s.to_i}, true, true))
18
- define_parameter_type(ParameterType.new('float', FLOAT_REGEXP, Float, lambda {|s| s.to_f}, true, false))
19
- define_parameter_type(ParameterType.new('word', WORD_REGEXP, String, lambda {|s| s}, false, false))
20
- define_parameter_type(ParameterType.new('string', STRING_REGEXP, String, lambda {|s| s.gsub(/\\"/, '"').gsub(/\\'/, "'")}, true, false))
17
+ define_parameter_type(ParameterType.new('int', INTEGER_REGEXPS, Integer, lambda {|s=nil| s && s.to_i}, true, true))
18
+ define_parameter_type(ParameterType.new('float', FLOAT_REGEXP, Float, lambda {|s=nil| s && s.to_f}, true, false))
19
+ define_parameter_type(ParameterType.new('word', WORD_REGEXP, String, lambda {|s=nil| s}, false, false))
20
+ define_parameter_type(ParameterType.new('string', STRING_REGEXP, String, lambda {|s=nil| s && s.gsub(/\\"/, '"').gsub(/\\'/, "'")}, true, false))
21
21
  end
22
22
 
23
23
  def lookup_by_type_name(name)
@@ -42,10 +42,12 @@ module Cucumber
42
42
  end
43
43
 
44
44
  def define_parameter_type(parameter_type)
45
- if @parameter_type_by_name.has_key?(parameter_type.name)
46
- raise CucumberExpressionError.new("There is already a parameter with name #{parameter_type.name}")
45
+ if parameter_type.name
46
+ if @parameter_type_by_name.has_key?(parameter_type.name)
47
+ raise CucumberExpressionError.new("There is already a parameter with name #{parameter_type.name}")
48
+ end
49
+ @parameter_type_by_name[parameter_type.name] = parameter_type
47
50
  end
48
- @parameter_type_by_name[parameter_type.name] = parameter_type
49
51
 
50
52
  parameter_type.regexps.each do |parameter_type_regexp|
51
53
  parameter_types = @parameter_types_by_regexp[parameter_type_regexp]
@@ -20,7 +20,7 @@ module Cucumber
20
20
  @expression_regexp,
21
21
  text
22
22
  ) || ParameterType.new(
23
- parameter_type_regexp,
23
+ nil,
24
24
  parameter_type_regexp,
25
25
  String,
26
26
  lambda {|*s| s[0]},
@@ -76,6 +76,12 @@ module Cucumber
76
76
  expect(match("{float}", ".22")).to eq([0.22])
77
77
  end
78
78
 
79
+ '[]()$.|?*+'.split('').each do |char|
80
+ it "does not allow parameter type with #{char}" do
81
+ expect {match("{#{char}string}", "something")}.to raise_error("Illegal character '#{char}' in parameter name {#{char}string}")
82
+ end
83
+ end
84
+
79
85
  it "throws unknown parameter type" do
80
86
  expect {match("{unknown}", "something")}.to raise_error('Undefined parameter type {unknown}')
81
87
  end
@@ -43,11 +43,11 @@ module Cucumber
43
43
  end
44
44
  end
45
45
 
46
- describe "Custom parameter" do
46
+ describe "Custom parameter type" do
47
47
  before do
48
- parameter_registry = ParameterTypeRegistry.new
48
+ parameter_type_registry = ParameterTypeRegistry.new
49
49
  ### [add-color-parameter-type]
50
- parameter_registry.define_parameter_type(ParameterType.new(
50
+ parameter_type_registry.define_parameter_type(ParameterType.new(
51
51
  'color', # name
52
52
  /red|blue|yellow/, # regexp
53
53
  Color, # type
@@ -56,7 +56,20 @@ module Cucumber
56
56
  false # prefer_for_regexp_match
57
57
  ))
58
58
  ### [add-color-parameter-type]
59
- @parameter_type_registry = parameter_registry
59
+ @parameter_type_registry = parameter_type_registry
60
+ end
61
+
62
+ it "throws exception for illegal character in parameter name" do
63
+ expect do
64
+ ParameterType.new(
65
+ '[string]',
66
+ /.*/,
67
+ String,
68
+ lambda {|s| s},
69
+ true,
70
+ false
71
+ )
72
+ end.to raise_error("Illegal character '[' in parameter name {[string]}")
60
73
  end
61
74
 
62
75
  describe CucumberExpression do
@@ -168,8 +181,18 @@ module Cucumber
168
181
  end
169
182
 
170
183
  describe RegularExpression do
171
- it "matches arguments with custom parameter type" do
172
- expression = RegularExpression.new(/I have a (red|blue|yellow) ball/, @parameter_type_registry)
184
+ it "matches arguments with custom parameter type without name" do
185
+ parameter_type_registry = ParameterTypeRegistry.new
186
+ parameter_type_registry.define_parameter_type(ParameterType.new(
187
+ nil,
188
+ /red|blue|yellow/,
189
+ Color,
190
+ lambda {|s| Color.new(s)},
191
+ true,
192
+ false
193
+ ))
194
+
195
+ expression = RegularExpression.new(/I have a (red|blue|yellow) ball/, parameter_type_registry)
173
196
  value = expression.match("I have a red ball")[0].value(nil)
174
197
  expect(value).to eq(Color.new('red'))
175
198
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cucumber-expressions
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aslak Hellesøy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-30 00:00:00.000000000 Z
11
+ date: 2018-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -134,7 +134,7 @@ rubyforge_project:
134
134
  rubygems_version: 2.7.6
135
135
  signing_key:
136
136
  specification_version: 4
137
- summary: cucumber-expressions-6.0.0
137
+ summary: cucumber-expressions-6.0.1
138
138
  test_files:
139
139
  - spec/capture_warnings.rb
140
140
  - spec/coverage.rb