From f38326fc4c859f2fdd4ee708ec377a20a12e50e5 Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Mon, 13 Oct 2008 22:14:51 +0200 Subject: [PATCH] Normalize spaces on input --- PciIds/DBQ.pm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/PciIds/DBQ.pm b/PciIds/DBQ.pm index 44f1614..cb82576 100644 --- a/PciIds/DBQ.pm +++ b/PciIds/DBQ.pm @@ -217,6 +217,15 @@ sub history( $$ ) { return $self->query( 'history', [ $addr ] ); } +sub spaceNorm( $ ) { + $_ = shift; + return undef unless defined $_; + s/[ \t]+/ /g; + s/^\s//; + s/\s$//; + return $_; +} + sub submitItem( $$$ ) { my( $self, $data, $auth ) = @_; my( $addr ) = ( $data->{'address'} ); @@ -227,7 +236,7 @@ sub submitItem( $$$ ) { return( 'exists', undef ) if( defined( $self->item( $addr->get(), 0 ) ) ); eval { $self->command( 'newitem', [ $addr->get(), $addr->parent()->get() ] ); - $self->command( 'newhistory', [ $addr->get(), $auth->{'authid'}, $data->{'discussion'}, $data->{'name'}, $data->{'note'} ] ); + $self->command( 'newhistory', [ $addr->get(), $auth->{'authid'}, spaceNorm( $data->{'discussion'} ), spaceNorm( $data->{'name'} ), spaceNorm( $data->{'note'} ) ] ); }; if( $@ ) { $self->rollback(); @@ -239,10 +248,10 @@ sub submitItem( $$$ ) { sub submitHistory( $$$$ ) { my( $self, $data, $auth, $address ) = @_; if( $data->{'delete'} ) { - $self->command( 'newhistory', [ $address->get(), $auth->{'authid'}, $data->{'text'}, '', $data->{'note'} ], 1 ); + $self->command( 'newhistory', [ $address->get(), $auth->{'authid'}, spaceNorm( $data->{'text'} ), '', '' ], 1 ); } else { $data->{'name'} = undef if defined $data->{'name'} && $data->{'name'} eq ''; - $self->command( 'newhistory', [ $address->get(), $auth->{'authid'}, $data->{'text'}, $data->{'name'}, $data->{'note'} ], 1 ); + $self->command( 'newhistory', [ $address->get(), $auth->{'authid'}, spaceNorm( $data->{'text'} ), spaceNorm( $data->{'name'} ), spaceNorm( $data->{'note'} ) ], 1 ); } return $self->last(); } -- 2.39.2