diff --git a/NEWS.md b/NEWS.md index 7d90d7bb..9c09d509 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,15 @@ ## Current Release +### Changes + +- `regexp` and `not_regexp` no longer try to change the regexes. + MariaDB, MySQL and PostgreSQL perfectly support PRCE, hence we + no longer try to rewrite the regexes. + Note that `regexp_replace` did not perform any of these rewritings. + +## Release v2.1.7/v1.3.7 + ### New Features - `o.format_date` as an alternative to `o.format` diff --git a/lib/arel_extensions/comparators.rb b/lib/arel_extensions/comparators.rb index 1f144e8a..b31c81ee 100644 --- a/lib/arel_extensions/comparators.rb +++ b/lib/arel_extensions/comparators.rb @@ -19,40 +19,13 @@ def <=(other) # REGEXP function # Pattern matching using regular expressions def =~(other) - # arg = self.relation.engine.connection.schema_cache.columns_hash(self.relation.table_name)[self.name.to_s].type - # if arg == :string || arg == :text - Arel::Nodes::Regexp.new self, convert_regexp(other) - # end + Arel::Nodes::Regexp.new self, Arel.quoted(other, self) end # NOT_REGEXP function # Negation of Regexp def !~(other) - # arg = self.relation.engine.connection.schema_cache.columns_hash(self.relation.table_name)[self.name.to_s].type - # if arg == :string || arg == :text - Arel::Nodes::NotRegexp.new self, convert_regexp(other) - # end - end - - private - - # Function used for not_regexp. - def convert_regexp(other) - case other - when String - # Do nothing. - when Regexp - other = other.source.gsub('\A', '^') - other.gsub!('\z', '$') - other.gsub!('\Z', '$') - other.gsub!('\d', '[0-9]') - other.gsub!('\D', '[^0-9]') - other.gsub!('\w', '[0-9A-Za-z]') - other.gsub!('\W', '[^A-Za-z0-9_]') - else - raise(ArgumentError) - end - Arel.quoted(other, self) + Arel::Nodes::NotRegexp.new self, Arel.quoted(other, self) end end end