[otrs-cvs] ImportExport/Kernel/System ImportExport.pm,1.20,1.21

cvs-log at otrs.org cvs-log at otrs.org
Wed Mar 26 17:34:36 GMT 2008


Comments:
Update of /home/cvs/ImportExport/Kernel/System
In directory lancelot:/tmp/cvs-serv8473/Kernel/System

Modified Files:
	ImportExport.pm 
Log Message:
Fixed bug# 2807 - Trimming of some input fields is missing or incorrect.

Author: mh

Index: ImportExport.pm
===================================================================
RCS file: /home/cvs/ImportExport/Kernel/System/ImportExport.pm,v
retrieving revision 1.20
retrieving revision 1.21
diff -C2 -d -r1.20 -r1.21
*** ImportExport.pm	26 Mar 2008 13:04:15 -0000	1.20
--- ImportExport.pm	26 Mar 2008 17:34:31 -0000	1.21
***************
*** 84,88 ****
  
      my $TemplateList = $ImportExportObject->TemplateList(
!         Object => 'Ticket',
          UserID => 1,
      );
--- 84,89 ----
  
      my $TemplateList = $ImportExportObject->TemplateList(
!         Object => 'Ticket',  # (optional)
!         Format => 'CSV'      # (optional)
          UserID => 1,
      );
***************
*** 94,117 ****
  
      # check needed stuff
!     for my $Argument (qw(Object UserID)) {
!         if ( !$Param{$Argument} ) {
!             $Self->{LogObject}->Log(
!                 Priority => 'error',
!                 Message  => "Need $Argument!"
!             );
!             return;
!         }
      }
  
      # quote
!     $Param{Object} = $Self->{DBObject}->Quote( $Param{Object} );
      $Param{UserID} = $Self->{DBObject}->Quote( $Param{UserID}, 'Integer' );
  
      # ask database
!     $Self->{DBObject}->Prepare(
!         SQL => "SELECT id FROM imexport_template WHERE "
!             . "imexport_object = '$Param{Object}' "
!             . "ORDER BY id",
!     );
  
      # fetch the result
--- 95,127 ----
  
      # check needed stuff
!     if ( !$Param{UserID} ) {
!         $Self->{LogObject}->Log(
!             Priority => 'error',
!             Message  => 'Need UserID!',
!         );
!         return;
      }
  
      # quote
!     for my $Argument (qw(Object Format)) {
!         $Param{$Argument} = $Self->{DBObject}->Quote( $Param{$Argument} ) || '';
!     }
      $Param{UserID} = $Self->{DBObject}->Quote( $Param{UserID}, 'Integer' );
  
+     # create sql string
+     my $SQL = 'SELECT id FROM imexport_template WHERE 1=1 ';
+ 
+     if ( $Param{Object} ) {
+         $SQL .= "AND imexport_object = '$Param{Object}' ";
+     }
+     if ( $Param{Format} ) {
+         $SQL .= "AND imexport_format = '$Param{Format}' ";
+     }
+ 
+     # add order option
+     $SQL .= 'ORDER BY id';
+ 
      # ask database
!     $Self->{DBObject}->Prepare( SQL => $SQL );
  
      # fetch the result
***************
*** 232,243 ****
      }
  
-     # cleanup template name
-     for my $Element (qw(Object Format Name)) {
-         $Param{$Element} =~ s{ [\n\r\f] }{}xmsg;    # RemoveAllNewlines
-         $Param{$Element} =~ s{ \t       }{}xmsg;    # RemoveAllTabs
-         $Param{$Element} =~ s{ \A \s+   }{}xmsg;    # TrimLeft
-         $Param{$Element} =~ s{ \s+ \z   }{}xmsg;    # TrimRight
-     }
- 
      # set default values
      $Param{Comment} = $Param{Comment} || '';
--- 242,245 ----
***************
*** 251,254 ****
--- 253,273 ----
      }
  
+     # cleanup given params (replace it with StringClean() in OTRS 2.3 and later)
+     for my $Argument (qw(Object Format)) {
+         $Self->_StringClean(
+             StringRef         => \$Param{$Argument},
+             RemoveAllNewlines => 1,
+             RemoveAllTabs     => 1,
+             RemoveAllSpaces   => 1,
+         );
+     }
+     for my $Argument (qw(Name Comment)) {
+         $Self->_StringClean(
+             StringRef         => \$Param{$Argument},
+             RemoveAllNewlines => 1,
+             RemoveAllTabs     => 1,
+         );
+     }
+ 
      # find exiting template with same name
      $Self->{DBObject}->Prepare(
***************
*** 328,337 ****
      }
  
-     # cleanup template name
-     $Param{Name} =~ s{ [\n\r\f] }{}xmsg;    # RemoveAllNewlines
-     $Param{Name} =~ s{ \t       }{}xmsg;    # RemoveAllTabs
-     $Param{Name} =~ s{ \A \s+   }{}xmsg;    # TrimLeft
-     $Param{Name} =~ s{ \s+ \z   }{}xmsg;    # TrimRight
- 
      # set default values
      $Param{Comment} = $Param{Comment} || '';
--- 347,350 ----
***************
*** 345,348 ****
--- 358,370 ----
      }
  
+     # cleanup given params (replace it with StringClean() in OTRS 2.3 and later)
+     for my $Argument (qw(Name Comment)) {
+         $Self->_StringClean(
+             StringRef         => \$Param{$Argument},
+             RemoveAllNewlines => 1,
+             RemoveAllTabs     => 1,
+         );
+     }
+ 
      # get the object of this template id
      $Self->{DBObject}->Prepare(
***************
*** 2175,2178 ****
--- 2197,2254 ----
  }
  
+ =item _StringClean()
+ 
+ DON'T USE THIS INTERNAL FUNCTION IN OTHER MODULES!
+ 
+ This function can be replaced with Kernel::System::CheckItem::StringClean() in OTRS 2.3 and later!
+ 
+ clean a given string
+ 
+     my $Error = $CheckItemObject->_StringClean(
+         StringRef         => \'String',
+         TrimLeft          => 0,  # (optional) default 1
+         TrimRight         => 0,  # (optional) default 1
+         RemoveAllNewlines => 1,  # (optional) default 0
+         RemoveAllTabs     => 1,  # (optional) default 0
+         RemoveAllSpaces   => 1,  # (optional) default 0
+     );
+ 
+ =cut
+ 
+ sub _StringClean {
+     my ( $Self, %Param ) = @_;
+ 
+     if ( !$Param{StringRef} || ref $Param{StringRef} ne 'SCALAR' ) {
+         $Self->{LogObject}->Log(
+             Priority => 'error',
+             Message  => 'Need a scalar reference!'
+         );
+         return;
+     }
+ 
+     return 1 if !${ $Param{StringRef} };
+ 
+     # set default values
+     $Param{TrimLeft}  = defined $Param{TrimLeft}  ? $Param{TrimLeft}  : 1;
+     $Param{TrimRight} = defined $Param{TrimRight} ? $Param{TrimRight} : 1;
+ 
+     my %TrimAction = (
+         RemoveAllNewlines => qr{ [\n\r\f] }xms,
+         RemoveAllTabs     => qr{ \t       }xms,
+         RemoveAllSpaces   => qr{ [ ]      }xms,
+         TrimLeft          => qr{ \A \s+   }xms,
+         TrimRight         => qr{ \s+ \z   }xms,
+     );
+ 
+     ACTION:
+     for my $Action ( sort keys %TrimAction ) {
+         next ACTION if !$Param{$Action};
+ 
+         ${ $Param{StringRef} } =~ s{ $TrimAction{$Action} }{}xmsg;
+     }
+ 
+     return 1;
+ }
+ 
  1;
  


More information about the cvs-log mailing list