From cf453de40ea9e8f70069b11890d52a09d96d441a Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Wed, 26 Feb 2020 11:47:50 -0800 Subject: Convert the node[:platform_version] to a Chef::VersionString `node[:platform_version] =~ "~> 1.2"` will now just work. This might conceivably be breaking if people are doing really weird things by the class changing (Chef::VersionString still inherits from String though, so it'll have to be weirdness on par with the bad `thing.class.to_s == "Mash"` kind of comparisons that were in ohai). Signed-off-by: Lamont Granquist --- chef-utils/lib/chef-utils/version_string.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'chef-utils') diff --git a/chef-utils/lib/chef-utils/version_string.rb b/chef-utils/lib/chef-utils/version_string.rb index 7a7096909f..e0888b346e 100644 --- a/chef-utils/lib/chef-utils/version_string.rb +++ b/chef-utils/lib/chef-utils/version_string.rb @@ -27,8 +27,13 @@ module ChefUtils # # @param val [String] Version string to parse. def initialize(val) - super - @parsed_version = ::Gem::Version.create(self) + val = "" unless val + super(val) + begin + @parsed_version = ::Gem::Version.create(self) + rescue ArgumentError + @parsed_version = nil + end end # @!group Compat wrappers for String @@ -135,7 +140,12 @@ module ChefUtils when Regexp super else - Gem::Requirement.create(other) =~ parsed_version + begin + Gem::Requirement.create(other) =~ parsed_version + rescue ArgumentError + # one side of the comparison wasn't parseable + super + end end end -- cgit v1.2.1