[freeside-commits] branch FREESIDE_2_3_BRANCH updated. 56138a845f0928d8c189ef962b430b3466bd3fc2

Ivan ivan at 420.am
Thu Feb 7 21:09:24 PST 2013


The branch, FREESIDE_2_3_BRANCH has been updated
       via  56138a845f0928d8c189ef962b430b3466bd3fc2 (commit)
      from  330c49dfeabc23f3340bdf6828ee1330f1f515d8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 56138a845f0928d8c189ef962b430b3466bd3fc2
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Thu Feb 7 21:09:18 2013 -0800

    fix leading and trailing spaces in customer,, contact, prospect names and companies, RT#19860

diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index b451086..80d8296 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -2626,10 +2626,29 @@ sub ut_name {
 #  warn "ut_name allowed alphanumerics: +(sort grep /\w/, map { chr() } 0..255), "\n";
   $self->getfield($field) =~ /^([\w \,\.\-\']+)$/
     or return gettext('illegal_name'). " $field: ". $self->getfield($field);
-  $self->setfield($field,$1);
+  my $name = $1;
+  $name =~ s/^\s+//; 
+  $name =~ s/\s+$//; 
+  $name =~ s/\s+/ /g;
+  $self->setfield($field, $name);
   '';
 }
 
+=item ut_namen COLUMN
+
+Check/untaint proper names; allows alphanumerics, spaces and the following
+punctuation: , . - '
+
+May not be null.
+
+=cut
+
+sub ut_namen {
+  my( $self, $field ) = @_;
+  return $self->setfield($field, '') if $self->getfield($field) =~ /^$/;
+  $self->ut_name($field);
+}
+
 =item ut_zip COLUMN
 
 Check/untaint zip codes.
diff --git a/FS/FS/contact.pm b/FS/FS/contact.pm
index 0b50dcc..936d47c 100644
--- a/FS/FS/contact.pm
+++ b/FS/FS/contact.pm
@@ -324,8 +324,8 @@ sub check {
     || $self->ut_foreign_keyn('prospectnum', 'prospect_main', 'prospectnum')
     || $self->ut_foreign_keyn('custnum', 'cust_main', 'custnum')
     || $self->ut_foreign_keyn('locationnum', 'cust_location', 'locationnum')
-    || $self->ut_textn('last')
-    || $self->ut_textn('first')
+    || $self->ut_namen('last')
+    || $self->ut_namen('first')
     || $self->ut_textn('title')
     || $self->ut_textn('comment')
     || $self->ut_enum('disabled', [ '', 'Y' ])
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index 3b2ba33..b333f95 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -1814,6 +1814,12 @@ sub check {
   $self->set_coord
     unless $import || ($self->latitude && $self->longitude);
 
+  my $company = $self->company;
+  $company =~ s/^\s+//; 
+  $company =~ s/\s+$//; 
+  $company =~ s/\s+/ /g;
+  $self->company($company);
+
   #barf.  need message catalogs.  i18n.  etc.
   $error .= "Please select an advertising source."
     if $error =~ /^Illegal or empty \(numeric\) refnum: /;
@@ -5131,6 +5137,26 @@ sub _upgrade_data { #class method
   local($ignore_banned_card) = 1;
   local($skip_fuzzyfiles) = 1;
   local($import) = 1; #prevent automatic geocoding (need its own variable?)
+
+  unless ( FS::upgrade_journal->is_done('cust_main__trimspaces') ) {
+
+    foreach my $cust_main ( qsearch({
+      'table'     => 'cust_main', 
+      'hashref'   => {},
+      'extra_sql' => 'WHERE '.
+                       join(' OR ',
+                         map "$_ LIKE ' %' OR $_ LIKE '% ' OR $_ LIKE '%  %'",
+                           qw( first last company )
+                       ),
+    }) ) {
+      my $error = $cust_main->replace;
+      die $error if $error;
+    }
+
+    FS::upgrade_journal->set_done('cust_main__trimspaces');
+
+  }
+
   $class->_upgrade_otaker(%opts);
 
 }
diff --git a/FS/FS/prospect_main.pm b/FS/FS/prospect_main.pm
index 5a4048f..a963fee 100644
--- a/FS/FS/prospect_main.pm
+++ b/FS/FS/prospect_main.pm
@@ -208,6 +208,12 @@ sub check {
   ;
   return $error if $error;
 
+  my $company = $self->company;
+  $company =~ s/^\s+//; 
+  $company =~ s/\s+$//; 
+  $company =~ s/\s+/ /g;
+  $self->company($company);
+
   $self->SUPER::check;
 }
 

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Record.pm        |   21 ++++++++++++++++++++-
 FS/FS/contact.pm       |    4 ++--
 FS/FS/cust_main.pm     |   26 ++++++++++++++++++++++++++
 FS/FS/prospect_main.pm |    6 ++++++
 4 files changed, 54 insertions(+), 3 deletions(-)




More information about the freeside-commits mailing list