From: Ivan Kohler Date: Fri, 8 Feb 2013 05:09:18 +0000 (-0800) Subject: fix leading and trailing spaces in customer,, contact, prospect names and companies... X-Git-Url: http://git.freeside.biz/gitweb/?a=commitdiff_plain;h=56138a845f0928d8c189ef962b430b3466bd3fc2;p=freeside.git 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 b451086c1..80d829608 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 0b50dcc98..936d47cd0 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 3b2ba3382..b333f9509 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 5a4048f51..a963feeb9 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; }