Skip to content

Commit

Permalink
5985 - 1.1.0 regex incompatible with 0.4.9
Browse files Browse the repository at this point in the history
Send fact matches with the surrounding /'s and deal with them
in our has_fact? method to deal with the new format
  • Loading branch information
ripienaar committed Jan 30, 2011
1 parent 0b9b2c7 commit 97073ce
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
9 changes: 8 additions & 1 deletion lib/mcollective/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ def self.has_fact?(fact, value, operator)
fact = Facts.get_fact(fact).clone

if operator == '=~'
# to maintain backward compat we send the value
# as /.../ which is what 1.0.x needed. this strips
# off the /'s wich is what we need here
if value =~ /^\/(.+)\/$/
value = $1
end

return true if fact.match(Regexp.new(value))

elsif operator == "=="
Expand Down Expand Up @@ -163,7 +170,7 @@ def self.parse_fact_string(fact)
elsif fact =~ /^([^ ]+?)[ ]*(<=|>=|<|>|!=|==|=~)[ ]*(.+)/
return {:fact => $1, :value => $3, :operator => $2 }
elsif fact =~ /^(.+?)[ ]*=[ ]*\/(.+)\/$/
return {:fact => $1, :value => $2, :operator => '=~' }
return {:fact => $1, :value => "/#{$2}/", :operator => '=~' }
elsif fact =~ /^([^= ]+?)[ ]*=[ ]*(.+)/
return {:fact => $1, :value => $2, :operator => '==' }
end
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/util_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ module MCollective

describe "#parse_fact_string" do
it "should parse old style regex fact matches" do
Util.parse_fact_string("foo=/bar/").should == {:fact => "foo", :value => "bar", :operator => "=~"}
Util.parse_fact_string("foo = /bar/").should == {:fact => "foo", :value => "bar", :operator => "=~"}
Util.parse_fact_string("foo=/bar/").should == {:fact => "foo", :value => "/bar/", :operator => "=~"}
Util.parse_fact_string("foo = /bar/").should == {:fact => "foo", :value => "/bar/", :operator => "=~"}
end

it "should parse old style equality" do
Expand Down
1 change: 1 addition & 0 deletions website/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ title: Changelog

|Date|Description|Ticket|
|----|-----------|------|
|2011/01/30|Fix backward compatibility with old foo=/bar/ style fact searches|5985|
|2011/01/30|Documentation update to reflect correct default identity behavior|6073|
|2011/01/29|Let the YAML file force fact reloads when the files update|6057|
|2011/01/29|Add the ability for fact plugins to force fact invalidation|6057|
Expand Down

0 comments on commit 97073ce

Please sign in to comment.