Skip to content

Commit

Permalink
Escape period in JGrep.format float regex
Browse files Browse the repository at this point in the history
So that it doesn't match strings like `2012R2` as a float.

Fixes voxpupuli/facterdb#148
  • Loading branch information
rodjek committed Feb 27, 2020
1 parent de89686 commit 537a1bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/jgrep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def self.validate_filters(filters)
def self.format(kvalue, value)
if kvalue.to_s =~ /^\d+$/ && value.to_s =~ /^\d+$/
[Integer(kvalue), Integer(value)]
elsif kvalue.to_s =~ /^\d+.\d+$/ && value.to_s =~ /^\d+.\d+$/
elsif kvalue.to_s =~ /^\d+\.\d+$/ && value.to_s =~ /^\d+\.\d+$/
[Float(kvalue), Float(value)]
else
[kvalue, value]
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/jgrep_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ module JGrep
expect(result1.is_a?(String)).to eq(true)
expect(result2.is_a?(String)).to eq(true)
end

it 'should not format strings with a single [^\d\.] character' do
result1, result2 = JGrep.format("2012R2", "2008R2")
expect(result1).to be_a(String)
expect(result2).to be_a(String)
end
end

describe "#has_object?" do
Expand Down

0 comments on commit 537a1bf

Please sign in to comment.