mcollective-client 2.8.8 → 2.8.9

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
  SHA1:
3
- metadata.gz: fb16d0f4c651d8d8bda6c9a0643a908afea9ddcc
4
- data.tar.gz: 36de6a62d72f40972804cd820052d1bd5c7fc599
3
+ metadata.gz: 67b38bbfce7f0aba03c8178a28501d99894e3d2f
4
+ data.tar.gz: 657509db5b28a31967dfd16fc333da90c12eb605
5
5
  SHA512:
6
- metadata.gz: 992c3957cea99c1d5a64ee774a40bdf87806104a30c87616e4b2864c7f5c92da476400d1679b867ca4d9d054975d1e055e5d930d736d2a3226890b67cf5db906
7
- data.tar.gz: 591c2e50265b70db08c0ef894a86097ed2f6f7a0d029e0789be0724b38510ebb12e223d1aeab09bd5954158f6a6dd1b7b146d1214b2f08e4c4651fe1e11cd658
6
+ metadata.gz: f70b87a2142b39da0f78d9096b75f6a4177cefcc26cd15a42779973dcf6823a78ce7aa035431938c1bb93711ce0430f4eda062e771bb438e790f5c3b32d54e3b
7
+ data.tar.gz: 671f207d9cddb69f948499413c2867719a919252cf054af3fcb65e91b741fee6de75498be1900a49fc453cd2ef294da0ef34365a2c86eb554973c051efde5813
data/lib/mcollective.rb CHANGED
@@ -59,7 +59,7 @@ module MCollective
59
59
 
60
60
  MCollective::Vendor.load_vendored
61
61
 
62
- VERSION="2.8.8"
62
+ VERSION="2.8.9"
63
63
 
64
64
  def self.version
65
65
  VERSION
@@ -157,11 +157,6 @@ module MCollective
157
157
  return false
158
158
  end
159
159
 
160
- # Escape strings for evaluation
161
- if (l_compare.is_a?(String) && !(function_hash["operator"] =~ /=~|!=~/))
162
- r_compare = "\"#{r_compare}\""
163
- end
164
-
165
160
  # Do a regex comparison if right compare string is a regex
166
161
  if operator=~ /(=~|!=~)/
167
162
  # Fail if left compare value isn't a string
@@ -177,10 +172,40 @@ module MCollective
177
172
  return !!result
178
173
  end
179
174
  end
180
- # Otherwise evaluate the logical comparison
175
+ # Otherwise do a normal comparison while taking the type into account
181
176
  else
182
- l_compare = "\"#{l_compare}\"" if l_compare.is_a?(String)
183
- result = eval("#{l_compare} #{operator} #{r_compare}")
177
+ if l_compare.is_a? String
178
+ r_compare = r_compare.to_s
179
+ elsif r_compare.is_a? String
180
+ if l_compare.is_a? Numeric
181
+ r_compare = r_compare.strip
182
+ begin
183
+ r_compare = Integer(r_compare)
184
+ rescue ArgumentError
185
+ begin
186
+ r_compare = Float(r_compare)
187
+ rescue ArgumentError
188
+ raise ArgumentError, "invalid numeric value: #{r_compare}"
189
+ end
190
+ end
191
+ elsif l_compare.is_a? TrueClass or l_compare.is_a? FalseClass
192
+ r_compare = r_compare.strip
193
+ if r_compare == true.to_s
194
+ r_compare = true
195
+ elsif r_compare == false.to_s
196
+ r_compare = false
197
+ else
198
+ raise ArgumentError, "invalid boolean value: #{r_compare}"
199
+ end
200
+ end
201
+ end
202
+ operator = operator.strip
203
+ if operator =~ /(?:(!=|<=|>=|<|>)|==?)/
204
+ operator = $1 ? $1.to_sym : :==
205
+ else
206
+ raise ArgumentError, "invalid operator: #{operator}"
207
+ end
208
+ result = l_compare.send(operator, r_compare)
184
209
  return result
185
210
  end
186
211
  end
@@ -65,7 +65,6 @@ module MCollective
65
65
  current_token_value = ""
66
66
  j = @token_index
67
67
  escaped = false
68
- escaped_with = ""
69
68
 
70
69
  begin
71
70
  if (@arguments[j] == "/")
@@ -117,47 +116,46 @@ module MCollective
117
116
  break
118
117
  end
119
118
 
120
- if @arguments[j+1] == "("
119
+ if @arguments[j] == "("
121
120
  func = true
122
- be_greedy = true
123
- end
124
-
125
- if @arguments[j+1] == '"' || @arguments[j+1] == "'"
126
- func = false
127
- be_greedy = true
128
- escaped = true
129
- escaped_with = @arguments[j+1]
130
- end
131
121
 
132
- current_token_value << @arguments[j]
122
+ current_token_value << @arguments[j]
123
+ j += 1
133
124
 
134
- if be_greedy
135
- if func
136
- while !(j+1 >= @arguments.size) && @arguments[j] != ')'
125
+ while j < @arguments.size
126
+ current_token_value << @arguments[j]
127
+ if @arguments[j] == ')'
137
128
  j += 1
138
- current_token_value << @arguments[j]
129
+ break
139
130
  end
140
- else
141
- j += 2 # step over first "
142
- @white_spaces += 1
143
- # identified "..."
144
- while !(j+1 >= @arguments.size) && @arguments[j] != escaped_with
145
- if @arguments[j] == '\\'
146
- # eat the escape char but don't add it to the token, or we
147
- # end up with \\\"
148
- @white_spaces += 1
149
- j += 1
150
- escaped = true
131
+ j += 1
132
+ end
133
+ elsif @arguments[j] == '"' || @arguments[j] == "'"
134
+ escaped = true
135
+ escaped_with = @arguments[j]
136
+
137
+ j += 1 # step over first " or '
138
+ @white_spaces += 1
139
+ # identified "..." or '...'
140
+ while j < @arguments.size
141
+ if @arguments[j] == '\\'
142
+ # eat the escape char but don't add it to the token, or we
143
+ # end up with \\\"
144
+ j += 1
145
+ @white_spaces += 1
146
+ unless j < @arguments.size
147
+ break
151
148
  end
152
- current_token_value << @arguments[j]
149
+ elsif @arguments[j] == escaped_with
153
150
  j += 1
151
+ @white_spaces += 1
152
+ break
154
153
  end
155
- @white_spaces += 1
154
+ current_token_value << @arguments[j]
155
+ j += 1
156
156
  end
157
-
158
- j += 1
159
- be_greedy = false
160
157
  else
158
+ current_token_value << @arguments[j]
161
159
  j += 1
162
160
  end
163
161
 
@@ -218,7 +218,7 @@ module MCollective
218
218
  def self.uuid(string=nil)
219
219
  string ||= OpenSSL::Random.random_bytes(16).unpack('H*').shift
220
220
 
221
- uuid_name_space_dns = "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8"
221
+ uuid_name_space_dns = [0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8].map {|b| b.chr}.join
222
222
 
223
223
  sha1 = Digest::SHA1.new
224
224
  sha1.update(uuid_name_space_dns)
@@ -105,8 +105,8 @@ module MCollective
105
105
  end
106
106
 
107
107
  it "should parse complex fstatements and statements with operators seperated by whitespaces" do
108
- parser = Parser.new("foo('bar').value = 1 and foo=bar or foo = bar")
109
- parser.execution_stack.should == [{"fstatement"=>"foo('bar').value=1"}, {"and"=>"and"}, {"statement"=>"foo=bar"}, {"or"=>"or"}, {"statement"=>"foo=bar"}]
108
+ parser = Parser.new(%q(foo('bar').value = 1 and foo=bar or foo = bar and baz("abc") = "xyz"))
109
+ parser.execution_stack.should == [{"fstatement"=>"foo('bar').value=1"}, {"and"=>"and"}, {"statement"=>"foo=bar"}, {"or"=>"or"}, {"statement"=>"foo=bar"}, {"and"=>"and"}, {"fstatement"=>'baz("abc")=xyz'}]
110
110
  end
111
111
 
112
112
  it "should parse statements where classes are mixed with fact comparisons and fstatements" do
@@ -262,6 +262,22 @@ module MCollective
262
262
  result.should == true
263
263
  end
264
264
 
265
+ it "should handle integer literals" do
266
+ Matcher.expects(:execute_function).returns(10)
267
+ @function_hash["r_compare"] = "0xa"
268
+ @function_hash["operator"] = "="
269
+ result = Matcher.eval_compound_fstatement(@function_hash)
270
+ result.should == true
271
+ end
272
+
273
+ it "should handle float literals" do
274
+ Matcher.expects(:execute_function).returns(50)
275
+ @function_hash["r_compare"] = "0.5e2"
276
+ @function_hash["operator"] = "="
277
+ result = Matcher.eval_compound_fstatement(@function_hash)
278
+ result.should == true
279
+ end
280
+
265
281
  it "should return true if we do a false=false comparison" do
266
282
  Matcher.expects(:execute_function).returns(false)
267
283
  @function_hash["r_compare"] = false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mcollective-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.8
4
+ version: 2.8.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet Labs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-11 00:00:00.000000000 Z
11
+ date: 2016-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: systemu