diff --git a/app/models/item/search/query.rb b/app/models/item/search/query.rb index f335b400..089afea7 100644 --- a/app/models/item/search/query.rb +++ b/app/models/item/search/query.rb @@ -62,11 +62,17 @@ class Item when 'restricts' is_positive ? Filter.restricts(value) : Filter.not_restricts(value) when 'fits' - color_name, species_name = value.split("-") - pet_type = load_pet_type_by_name(color_name, species_name) - is_positive ? - Filter.fits_pet_type(pet_type, color_name:, species_name:) : - Filter.not_fits_pet_type(pet_type, color_name:, species_name:) + match = value.match(/^([^-]+)-([^-]+)$/) + if match.present? + color_name, species_name = match.captures + pet_type = load_pet_type_by_name(color_name, species_name) + return is_positive ? + Filter.fits_pet_type(pet_type, color_name:, species_name:) : + Filter.not_fits_pet_type(pet_type, color_name:, species_name:) + end + message = I18n.translate('items.search.errors.not_found.fits_target', + value: value) + raise Item::Search::Error, message when 'species' begin species = Species.find_by_name!(value) diff --git a/config/locales/en.yml b/config/locales/en.yml index 268cc883..2e1afe07 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -361,6 +361,8 @@ en: alt_style: We have no record of the "%{filter_text}" alt style. Is it spelled correctly? pet_type_id: We have no record of pet type %{id}. Weird. + fits_target: I'm not sure what "fits:%{value}" means. You can + use "fits:blue-acara", "fits:nostalgic-faerie-draik", or similar! not_logged_in: The "user" filters are only available if you're logged in. flag_keywords: is: is