X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FRecord.pm;h=6409da33d68549996d1299840bc6e1e5ab746f45;hb=6b86dff993093cc34ca370ec8352103a7f3208f8;hp=113e1a18df73519212cb1cb801dc46d80101249d;hpb=018f6678557506e68cc6b8643862143cc332f7da;p=freeside.git diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 113e1a18d..6409da33d 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -73,7 +73,8 @@ FS::Record - Database record objects $value = $record->ut_alpha('column'); $value = $record->ut_alphan('column'); $value = $record->ut_phonen('column'); - $value = $record->ut_anythingn('column'); + $value = $record->ut_anything('column'); + $value = $record->ut_name('column'); $dbdef = reload_dbdef; $dbdef = reload_dbdef "/non/standard/filename"; @@ -169,6 +170,8 @@ objects. sub qsearch { my($table, $record, $select, $extra_sql ) = @_; + $table =~ /^([\w\_]+)$/ or die "Illegal table: $table"; + $table = $1; $select ||= '*'; my $dbh = dbh; @@ -196,7 +199,7 @@ sub qsearch { $sth->execute( map $record->{$_}, grep defined( $record->{$_} ) && $record->{$_} ne '', @fields - ) or croak $dbh->errstr; + ) or croak "Error executing \"$statement\": ". $dbh->errstr; $dbh->commit or croak $dbh->errstr if $FS::UID::AutoCommit; if ( eval 'scalar(@FS::'. $table. '::ISA);' ) { @@ -313,6 +316,8 @@ sub AUTOLOAD { my($field)=$AUTOLOAD; $field =~ s/.*://; if ( defined($value) ) { + confess "errant AUTOLOAD $field for $self (arg $value)" + unless $self->can('setfield'); $self->setfield($field,$value); } else { $self->getfield($field); @@ -785,8 +790,37 @@ sub ut_domain { ''; } +=item ut_name COLUMN + +Check/untaint proper names; allows alphanumerics, spaces and the following +punctuation: , . - ' + +May not be null. + +=cut + +sub ut_name { + my( $self, $field ) = @_; + $self->getfield($field) =~ /^([\w \,\.\-\']+)$/ + or return "Illegal (name) $field: ". $self->getfield($field); + $self->setfield($field,$1); + ''; +} + +=item ut_zip COLUMN + +Check/untaint zip codes. + =cut +sub ut_zip { + my( $self, $field ) = @_; + $self->getfield($field) =~ /^\s*(\w[\w\-\s]{2,8}\w)\s*$/ + or return "Illegal (zip) $field: ". $self->getfield($field); + $self->setfield($field,$1); + ''; +} + =item ut_anything COLUMN Untaints arbitrary data. Be careful. @@ -795,7 +829,7 @@ Untaints arbitrary data. Be careful. sub ut_anything { my($self,$field)=@_; - $self->getfield($field) =~ /^(.*)$/ + $self->getfield($field) =~ /^(.*)$/s or return "Illegal $field: ". $self->getfield($field); $self->setfield($field,$1); ''; @@ -825,6 +859,8 @@ sub fields { $table_obj->columns; } +=back + =head1 SUBROUTINES =over 4 @@ -913,7 +949,7 @@ sub DESTROY { return; } =head1 VERSION -$Id: Record.pm,v 1.14 2001-04-15 12:56:30 ivan Exp $ +$Id: Record.pm,v 1.21 2001-08-11 05:50:52 ivan Exp $ =head1 BUGS @@ -943,7 +979,7 @@ The ut_money method assumes money has two decimal digits. The Pg money kludge in the new method only strips `$'. -The ut_phonen method assumes US-style phone numbers. +The ut_phonen method only checks US-style phone numbers. The _quote function should probably use ut_float instead of a regex. @@ -956,6 +992,8 @@ As of 1.14, DBI fetchall_hashref( {} ) doesn't set fetchrow_hashref NAME_lc, or allow it to be set. Working around it is ugly any way around - DBI should be fixed. (only affects RDBMS which return uppercase column names) +ut_zip should take an optional country like ut_phone. + =head1 SEE ALSO L, L, L