From e93d6a420bd1304d4f419884950493cb3cc60bed Mon Sep 17 00:00:00 2001 From: dbs Date: Thu, 14 Apr 2011 18:18:37 +0000 Subject: [PATCH] Escape rather than filter SIMILAR TO metacharacters in patron crazy search The filtering I introduced in r19983 was overly aggressive, and included characters that weren't actually SIMILAR TO metacharacters. Instead, escape each character, carefully going through the list of metacharacters listed at http://www.postgresql.org/docs/8.4/interactive/functions-matching.html Works for email addresses like "foo.bar+baz@example.com". git-svn-id: svn://svn.open-ils.org/ILS/trunk@20085 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Storage/Publisher/actor.pm | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/actor.pm index 6f8c498..cd3d4b5 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/actor.pm @@ -616,7 +616,18 @@ __PACKAGE__->register_method( sub _clean_regex_chars { my ($search) = @_; - $search =~ tr/\\.[]()?*+{}^$//d; + # Escape metacharacters for SIMILAR TO + # (http://www.postgresql.org/docs/8.4/interactive/functions-matching.html) + $search =~ s/\_/\\_/g; + $search =~ s/\%/\\%/g; + $search =~ s/\|/\\|/g; + $search =~ s/\*/\\*/g; + $search =~ s/\+/\\+/g; + $search =~ s/\[/\\[/g; + $search =~ s/\]/\\]/g; + $search =~ s/\(/\\(/g; + $search =~ s/\)/\\)/g; + return $search; } -- 1.7.2.5