@@ -45,7 +45,7 @@ class Condition
4545 CONTAINS => -> ( other_value , self_value ) { ( other_value || false ) && other_value . include? ( self_value ) } ,
4646
4747 NOT_CONTAINS => -> ( other_value , self_value ) { ( other_value || false ) && !other_value . include? ( self_value ) } ,
48- REGEX => -> ( other_value , self_value ) { ( other_value || false ) && other_value . match? ( self_value ) }
48+ REGEX => -> ( other_value , self_value ) { ( other_value || false ) && other_value . to_s . match? ( self_value ) }
4949 } . freeze
5050
5151 def initialize ( operator :, value :, property : nil )
@@ -55,11 +55,17 @@ def initialize(operator:, value:, property: nil)
5555 end
5656
5757 def match_trait_value? ( trait_value )
58- # handle some exceptions
59- trait_value = Semantic ::Version . new ( trait_value . gsub ( /:semver$/ , '' ) ) if @value . is_a? ( String ) && @value . match? ( /:semver$/ )
58+ if @value . is_a? ( String ) && @value . match? ( /:semver$/ )
59+ begin
60+ trait_value = Semantic ::Version . new ( trait_value . to_s . gsub ( /:semver$/ , '' ) )
61+ rescue StandardError
62+ return false
63+ end
64+ end
6065
6166 return match_in_value ( trait_value ) if @operator == IN
6267 return match_modulo_value ( trait_value ) if @operator == MODULO
68+ return MATCHING_FUNCTIONS [ REGEX ] &.call ( trait_value , @value ) if @operator == REGEX
6369
6470 type_as_trait_value = format_to_type_of ( trait_value )
6571 formatted_value = type_as_trait_value ? type_as_trait_value . call ( @value ) : @value
@@ -72,10 +78,17 @@ def format_to_type_of(input)
7278 {
7379 'String' => -> ( v ) { v . to_s } ,
7480 'Semantic::Version' => -> ( v ) { Semantic ::Version . new ( v . to_s . gsub ( /:semver$/ , '' ) ) } ,
81+ # Double check this is the desired behavior between SDKs
7582 'TrueClass' => -> ( v ) { [ 'True' , 'true' , 'TRUE' , true , 1 , '1' ] . include? ( v ) } ,
76- 'FalseClass' => -> ( v ) { ![ 'False' , 'false' , 'FALSE' , false , 0 , '0' ] . include? ( v ) } ,
77- 'Integer' => -> ( v ) { v . to_i } ,
78- 'Float' => -> ( v ) { v . to_f }
83+ 'FalseClass' => -> ( v ) { ![ 'False' , 'false' , 'FALSE' , false ] . include? ( v ) } ,
84+ 'Integer' => -> ( v ) {
85+ i = v . to_i ;
86+ i . to_s == v . to_s ? i : v
87+ } ,
88+ 'Float' => -> ( v ) {
89+ f = v . to_f ;
90+ f . to_s == v . to_s ? f : v
91+ }
7992 } [ input . class . to_s ]
8093 end
8194 # rubocop:enable Metrics/AbcSize
@@ -88,9 +101,23 @@ def match_modulo_value(trait_value)
88101 end
89102
90103 def match_in_value ( trait_value )
91- return @value . split ( ',' ) . include? ( trait_value . to_s ) if trait_value . is_a? ( String ) || trait_value . is_a? ( Integer )
104+ return false if trait_value . nil? || trait_value . is_a? ( TrueClass ) || trait_value . is_a? ( FalseClass )
92105
93- false
106+ if @value . is_a? ( Array )
107+ return @value . include? ( trait_value . to_s )
108+ end
109+
110+ if @value . is_a? ( String )
111+ begin
112+ parsed = JSON . parse ( @value )
113+ if parsed . is_a? ( Array )
114+ return parsed . include? ( trait_value . to_s )
115+ end
116+ rescue JSON ::ParserError
117+ end
118+ end
119+
120+ @value . to_s . split ( ',' ) . include? ( trait_value . to_s )
94121 end
95122
96123 class << self
0 commit comments