Skip to content

Commit

Permalink
Cast argument to string before performing regex
Browse files Browse the repository at this point in the history
Recently we started getting warnings about calling #=~ on things like
booleans and arrays etc.

This commit ensures that we cast the argument to a string before
performing a regex on it to ensure that we aren't relying on what
calling a regex match type method on a boolean returns.
  • Loading branch information
jacquesporveau committed May 20, 2020
1 parent 1ccba07 commit 427b490
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions core/lib/spree/preferences/preferable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ def convert_preference_value(value, type)
value.to_i
when :boolean
if !value ||
value == 0 ||
value =~ /\A(f|false|0)\Z/i ||
value.to_s =~ /\A(f|false|0|^)\Z/i ||
(value.respond_to?(:empty?) && value.empty?)
false
else
Expand Down

0 comments on commit 427b490

Please sign in to comment.