Skip to content

[BUG][RoR 7.1] ActiveRecord::normalizes can break cont predicate #1488

@AmShaegar13

Description

@AmShaegar13

When normalizing attributes using the new ActiveRecord::normalizes method, % could be tampered with.

class User < ActiveRecord::Base
  normalizes :name, with: ->(name) { name.gsub(/[^a-z0-9]/, '_') }
end

User.ransack({ name_cont: 'foo' }).result.to_sql
# => "SELECT \"users\".* FROM \"users\" WHERE \"users\".\"name\" LIKE '_foo_'"
#                                                                      ^   ^
#                                                                      %foo%

Failing test

In my opinion, this should not be possible as normalizes should only apply to the attribute itself and the search term but not the wildcards.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions