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

Search for strings containing leading whitespace is broken #1198

Closed
DCrow opened this issue Jan 20, 2021 · 4 comments
Closed

Search for strings containing leading whitespace is broken #1198

DCrow opened this issue Jan 20, 2021 · 4 comments

Comments

@DCrow
Copy link
Contributor

DCrow commented Jan 20, 2021

After #1115 ransack started removing whitespace from search queries.

It is now impossible to search for those kind of strings.
Some users in my project use names/label with leading spaces, so they depend on previous behavior.

Example

Person.ransack("name_start" => " Wilson").to_sql
# => "SELECT \"people\".* FROM \"people\" WHERE \"people\".\"name\" LIKE 'Wilson%' ORDER BY \"people\".\"id\" DESC"
# Expecting 
# => "SELECT \"people\".* FROM \"people\" WHERE \"people\".\"name\" LIKE ' Wilson%' ORDER BY \"people\".\"id\" DESC"

Maybe add some kind of option to turn off whitespace stripping?

@scarroll32
Copy link
Member

@DCrow that is a good point, I think the best option would be strip as default but to have a way to opt-out.

@scarroll32
Copy link
Member

This code could become something like:

    self.options = {
      :search_key => :q,
      :ignore_unknown_conditions => true,
      :hide_sort_order_indicators => false,
      :up_arrow => '▼'.freeze,
      :down_arrow => '▲'.freeze,
      :default_arrow => nil,
      :sanitize_scope_args => true,
      :postgres_fields_sort_option => nil,
      :strip_whitespace => true
    }

Which would give the ability to do:

Ransack.configure do |c|
  c.strip_whitespace = false
end

@DCrow
Copy link
Contributor Author

DCrow commented Feb 25, 2021

Seems good to me. Opt-out also seems logical since there might be projects which already utilize whitespace stripping.

Also maybe add some notes about this change(which version started whitespace stripping, etc) and option in README?

@scarroll32
Copy link
Member

Closed by #1214

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

2 participants