From 8e7bef39d76ae8b444b76930958dc0e26d48c5d3 Mon Sep 17 00:00:00 2001 From: mmeest Date: Mon, 9 Jun 2025 10:31:33 +0300 Subject: [PATCH] fix issue with idents with special character --- Gemfile.lock | 2 +- app/models/domain.rb | 48 ++++++++++++++++++++++++ app/services/partial_search_formatter.rb | 8 +++- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index aaa2d9a94..6244daa11 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -412,7 +412,7 @@ GEM request_store (~> 1.4) pdfkit (0.8.7.2) pg (1.5.9) - pg_query (2.1.2) + pg_query (0.9.0) google-protobuf (>= 3.17.1) pghero (3.1.0) activerecord (>= 6) diff --git a/app/models/domain.rb b/app/models/domain.rb index 809d18615..fcab13248 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -282,6 +282,54 @@ class Domain < ApplicationRecord authorizable_ransackable_attributes end + def ransackable_scopes(*) + [:registrant_ident_cont_any, :contacts_ident_cont_any] + end + + def registrant_ident_cont_any(value) + return all if value.blank? + + # Split the value into parts and create search conditions + parts = value.split('-') + conditions = [] + + # Add the original value + conditions << "contacts.ident ILIKE '%#{value}%'" + + # Add conditions for each part + parts.each do |part| + conditions << "contacts.ident ILIKE '%#{part}%'" + end + + # Add condition with hyphens removed + clean_value = value.gsub('-', '') + conditions << "REPLACE(contacts.ident, '-', '') ILIKE '%#{clean_value}%'" + + joins(:registrant).where(conditions.join(' OR ')) + end + + def contacts_ident_cont_any(value) + return all if value.blank? + + # Split the value into parts and create search conditions + parts = value.split('-') + conditions = [] + + # Add the original value + conditions << "contacts.ident ILIKE '%#{value}%'" + + # Add conditions for each part + parts.each do |part| + conditions << "contacts.ident ILIKE '%#{part}%'" + end + + # Add condition with hyphens removed + clean_value = value.gsub('-', '') + conditions << "REPLACE(contacts.ident, '-', '') ILIKE '%#{clean_value}%'" + + joins(:contacts).where(conditions.join(' OR ')) + end + def nameserver_required? Setting.nameserver_required end diff --git a/app/services/partial_search_formatter.rb b/app/services/partial_search_formatter.rb index aa783dc81..48cbf4cc0 100644 --- a/app/services/partial_search_formatter.rb +++ b/app/services/partial_search_formatter.rb @@ -5,7 +5,7 @@ class PartialSearchFormatter search_params.each do |key, value| next unless should_format?(key, value) - search_params[key] = format_value(value) + search_params[key] = format_value(value, key) end search_params @@ -15,9 +15,13 @@ class PartialSearchFormatter key.include?('matches') && value.present? end - def self.format_value(value) + def self.format_value(value, key) if value =~ /\A\*.*\*\z/ value.gsub(/\A\*|\*\z/, '') + elsif key.include?('ident') + # For contact identifiers, return array of values + parts = value.split('-') + parts.map { |part| "%#{part}%" } else "%#{value}%" end