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

Invalid combinators to raise ArgumentError #1465

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bagp1
Copy link

@bagp1 bagp1 commented Dec 4, 2023

Based on #1396

The reporter encountered two issues:

  1. Passing a combinator value as a symbol doesn't match the expected combinator.
  2. Invalid arguments silently misbehavior rather than raise argument errors even when the dangerous method #ransack! is called.

I can see why unrecognised combinators default to "AND", it's the more conservative, safe option. But it's very surprising and a potential source of bugs for downstream users. Also the users have intentionally called the dangerous method, so should be error handling as appropriate for their domain. The right thing to do is to raise on invalid args.

However we'd best minimize impact for users currently passing invalid args. The most obvious errors would be rather than passing the expected "or", they might be passing one of "OR", :or and not noticing the fault. We can correct behavior in these common cases by downcasing and converting to a string. Indeed Ransack already does conversion to a string in some pathways, just not as part of a search. Also Anything more exotic is really unrecognisable and an error.

This PR comes with a set of tests describing expected behavior and including a few that would have failed prior to the changes.

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

Successfully merging this pull request may close these issues.

1 participant