Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AmShaegar13 opened this issue Apr 11, 2024 · 0 comments
Open

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

AmShaegar13 opened this issue Apr 11, 2024 · 0 comments

Comments

@AmShaegar13
Copy link
Contributor

AmShaegar13 commented Apr 11, 2024

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.

@AmShaegar13 AmShaegar13 changed the title [BUG] ActiveRecord::normalizes can break cont predicate [BUG][RoR 7.1] ActiveRecord::normalizes can break cont predicate May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant