administrate icon indicating copy to clipboard operation
administrate copied to clipboard

Improve filter regex

Open rostixman opened this issue 3 years ago • 1 comments

What would you like to be able to do? Can you provide some examples?

I would like to be able to pass filter attribute in French, German, or other languages. Because now regex doesn't allow non-Latin characters.

In my case I have Mobility gem and want to search in other languages. I found solution with custom search method, but in my case it's enough to add this:

COLLECTION_FILTERS = {
    name: -> (resources, attr) { resources.search(attr) }
  }.freeze

and also I add search method to resource model with the logic that I need:

scope :search, -> (name_q) do
    i18n do
      name.lower.matches("%#{name_q&.downcase}%")
    end
  end

How could we go about implementing that? Switch \w to Unicode codes/ranges or word.match?(/^#{filter}:.*$/) but this way may be unsafe

Can you think of other approaches to the problem? Allow custom regex for filter attribute

rostixman avatar Jul 26 '22 19:07 rostixman

OK, so if I'm understanding correctly, the issue is with the following code, right?

https://github.com/thoughtbot/administrate/blob/5c278d7b38bde0db69e27779465fd4c99c8dc3ae/lib/administrate/search.rb#L33-L35

You are right that it should support Unicode. Do you want to provide a PR to fix it? :slightly_smiling_face:

pablobm avatar Jul 28 '22 13:07 pablobm