fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2010-11-03 06:06 am

[dw-free] Have LJ::text_trim use LJ::trim to remove trailing spaces from trimmed string

[commit: http://hg.dwscoalition.org/dw-free/rev/c0d254a358ac]

http://bugs.dwscoalition.org/show_bug.cgi?id=3191

After trimming the text to a specific length, also remove trailing and
leading spaces.

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/DW/Setting/AdultContentReason.pm
  • cgi-bin/DW/Setting/GoogleAnalytics.pm
  • cgi-bin/DW/Setting/StickyEntry.pm
  • cgi-bin/DW/User/ContentFilters.pm
  • cgi-bin/DW/User/ContentFilters/Filter.pm
  • cgi-bin/DW/User/Edges/WatchTrust.pm
  • cgi-bin/LJ/Setting/Name.pm
  • cgi-bin/LJ/Tags.pm
  • cgi-bin/LJ/User.pm
  • cgi-bin/ljlib.pl
  • cgi-bin/ljtextutil.pl
--------------------------------------------------------------------------------
diff -r cf6107425509 -r c0d254a358ac cgi-bin/DW/Setting/AdultContentReason.pm
--- a/cgi-bin/DW/Setting/AdultContentReason.pm	Wed Nov 03 13:57:33 2010 +0800
+++ b/cgi-bin/DW/Setting/AdultContentReason.pm	Wed Nov 03 14:05:40 2010 +0800
@@ -38,8 +38,7 @@ sub save {
 sub save {
     my ( $class, $u, $args ) = @_;
  
-    my $txt = $class->get_arg( $args, "reason" );
-    $txt = LJ::trim( $txt || "" );
+    my $txt = $class->get_arg( $args, "reason" ) || '';
     $txt = LJ::text_trim( $txt, 0, 255 );
     $u->set_prop( "adult_content_reason", $txt );
     return 1;
diff -r cf6107425509 -r c0d254a358ac cgi-bin/DW/Setting/GoogleAnalytics.pm
--- a/cgi-bin/DW/Setting/GoogleAnalytics.pm	Wed Nov 03 13:57:33 2010 +0800
+++ b/cgi-bin/DW/Setting/GoogleAnalytics.pm	Wed Nov 03 14:05:40 2010 +0800
@@ -53,8 +53,7 @@ sub save {
 sub save {
     my ( $class, $u, $args ) = @_;
 
-    my $txt = $class->get_arg( $args, "code" );
-    $txt = LJ::trim( $txt || "" );
+    my $txt = $class->get_arg( $args, "code" ) || '';
     $txt = LJ::text_trim( $txt, 0, 100 );
     # Check that the ID matches the format UA-number-number
     # or is blank before proceeding.
diff -r cf6107425509 -r c0d254a358ac cgi-bin/DW/Setting/StickyEntry.pm
--- a/cgi-bin/DW/Setting/StickyEntry.pm	Wed Nov 03 13:57:33 2010 +0800
+++ b/cgi-bin/DW/Setting/StickyEntry.pm	Wed Nov 03 14:05:40 2010 +0800
@@ -48,8 +48,7 @@ sub save {
 sub save {
     my ( $class, $u, $args ) = @_;
 
-    my $sticky = $class->get_arg( $args, "stickyid" );
-    $sticky = LJ::trim( $sticky || "" );
+    my $sticky = $class->get_arg( $args, "stickyid" ) || '';
     $sticky = LJ::text_trim( $sticky, 0, 100 );
     unless ( $u->sticky_entry ( $sticky ) ) {
         $class->errors( "stickyid" => $class->ml( 'setting.stickyentry.error.invalid' ) ) ;
diff -r cf6107425509 -r c0d254a358ac cgi-bin/DW/User/ContentFilters.pm
--- a/cgi-bin/DW/User/ContentFilters.pm	Wed Nov 03 13:57:33 2010 +0800
+++ b/cgi-bin/DW/User/ContentFilters.pm	Wed Nov 03 14:05:40 2010 +0800
@@ -109,7 +109,7 @@ sub create_content_filter {
     # filters you can create...
 
     # check if a filter with this name already exists, if so return its id, so the user can edit or remove it
-    my $name = LJ::trim( LJ::text_trim( delete $args{name}, 255, 100 ) ) || '';
+    my $name = LJ::text_trim( delete $args{name}, 255, 100 ) || '';
     return $u->content_filters( name => $name )->id
         if $u->content_filters( name => $name );
 
diff -r cf6107425509 -r c0d254a358ac cgi-bin/DW/User/ContentFilters/Filter.pm
--- a/cgi-bin/DW/User/ContentFilters/Filter.pm	Wed Nov 03 13:57:33 2010 +0800
+++ b/cgi-bin/DW/User/ContentFilters/Filter.pm	Wed Nov 03 14:05:40 2010 +0800
@@ -358,7 +358,7 @@ sub _getset {
     # FIXME: we should probably have generic vetters somewhere... or something, I don't know,
     # I just know that I don't really like doing this here
     if ( $which eq 'name' ) {
-        $val = LJ::trim( LJ::text_trim( $val, 255, 100 ) ) || '';
+        $val = LJ::text_trim( $val, 255, 100 ) || '';
     } elsif ( $which eq 'public' ) {
         $val = $val ? 1 : 0;
     } elsif ( $which eq 'sortorder' ) {
diff -r cf6107425509 -r c0d254a358ac cgi-bin/DW/User/Edges/WatchTrust.pm
--- a/cgi-bin/DW/User/Edges/WatchTrust.pm	Wed Nov 03 13:57:33 2010 +0800
+++ b/cgi-bin/DW/User/Edges/WatchTrust.pm	Wed Nov 03 14:05:40 2010 +0800
@@ -240,10 +240,10 @@ sub _del_wt_edge {
 
 # returns the valid version of a group name
 sub valid_group_name {
-    my $name = shift;
+    my $name = $_[0];
 
     # strip off trailing slash(es)
-    $name =~ s!/+$!!;
+    $name =~ s!/+\s*$!!;
 
     # conform to maxes
     $name = LJ::text_trim( $name, LJ::BMAX_GRPNAME2, LJ::CMAX_GRPNAME2 );
diff -r cf6107425509 -r c0d254a358ac cgi-bin/LJ/Setting/Name.pm
--- a/cgi-bin/LJ/Setting/Name.pm	Wed Nov 03 13:57:33 2010 +0800
+++ b/cgi-bin/LJ/Setting/Name.pm	Wed Nov 03 14:05:40 2010 +0800
@@ -50,7 +50,6 @@ sub error_check {
 
 sub save_text {
     my ($class, $u, $txt) = @_;
-    $txt = LJ::trim($txt);
     $txt = LJ::text_trim($txt, LJ::BMAX_NAME, LJ::CMAX_NAME);
     return 0 unless $u && $u->update_self( { name => $txt } );
     LJ::load_userid( $u->userid, "force" );
diff -r cf6107425509 -r c0d254a358ac cgi-bin/LJ/Tags.pm
--- a/cgi-bin/LJ/Tags.pm	Wed Nov 03 13:57:33 2010 +0800
+++ b/cgi-bin/LJ/Tags.pm	Wed Nov 03 14:05:40 2010 +0800
@@ -643,11 +643,9 @@ sub is_valid_tagstring {
     };
     my $canonical_tag = sub {
         my $tag = shift;
-        $tag = LJ::trim($tag);
         $tag =~ s/\s+/ /g; # condense multiple spaces to a single space
         $tag = LJ::text_trim($tag, LJ::BMAX_KEYWORD, LJ::CMAX_KEYWORD);
         $tag = LJ::utf8_lc( $tag );
-        $tag = LJ::trim( $tag ); # after trucating, there may be a trailing space
         return $tag;
     };
 
diff -r cf6107425509 -r c0d254a358ac cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm	Wed Nov 03 13:57:33 2010 +0800
+++ b/cgi-bin/LJ/User.pm	Wed Nov 03 14:05:40 2010 +0800
@@ -6080,7 +6080,7 @@ sub get_keyword_id
 
     # setup the keyword for use
     return 0 unless $kw =~ /\S/;
-    $kw = LJ::trim( LJ::text_trim( $kw, LJ::BMAX_KEYWORD, LJ::CMAX_KEYWORD ) );
+    $kw = LJ::text_trim( $kw, LJ::BMAX_KEYWORD, LJ::CMAX_KEYWORD );
 
     # get the keyword and insert it if necessary
     my $kwid = $u->selectrow_array( 'SELECT kwid FROM userkeywords WHERE userid = ? AND keyword = ?',
diff -r cf6107425509 -r c0d254a358ac cgi-bin/ljlib.pl
--- a/cgi-bin/ljlib.pl	Wed Nov 03 13:57:33 2010 +0800
+++ b/cgi-bin/ljlib.pl	Wed Nov 03 14:05:40 2010 +0800
@@ -1531,7 +1531,7 @@ sub get_sitekeyword_id {
 
     # setup the keyword for use
     return 0 unless $kw =~ /\S/;
-    $kw = LJ::trim( LJ::text_trim( LJ::trim( $kw ), LJ::BMAX_SITEKEYWORD, LJ::CMAX_SITEKEYWORD ) );
+    $kw = LJ::text_trim( $kw, LJ::BMAX_SITEKEYWORD, LJ::CMAX_SITEKEYWORD );
     $kw = LJ::utf8_lc( $kw ) unless $opts{allowmixedcase};
 
     # get the keyword and insert it if necessary
diff -r cf6107425509 -r c0d254a358ac cgi-bin/ljtextutil.pl
--- a/cgi-bin/ljtextutil.pl	Wed Nov 03 13:57:33 2010 +0800
+++ b/cgi-bin/ljtextutil.pl	Wed Nov 03 14:05:40 2010 +0800
@@ -431,11 +431,12 @@ sub text_trim
 sub text_trim
 {
     my ($text, $byte_max, $char_max) = @_;
+    $text = defined $text ? LJ::trim( $text ) : '';
     return $text unless $byte_max or $char_max;
     if (!$LJ::UNICODE) {
         $byte_max = $char_max if $char_max and $char_max < $byte_max;
         $byte_max = $char_max unless $byte_max;
-        return substr($text, 0, $byte_max);
+        return LJ::trim( substr( $text, 0, $byte_max ) );
     }
     my $cur = 0;
     my $utf_char = "([\x00-\x7f]|[\xc0-\xdf].|[\xe0-\xef]..|[\xf0-\xf7]...)";
@@ -451,7 +452,7 @@ sub text_trim
         $cur += length($1);
         $char_max--;
     }
-    return substr($text,0,$cur);
+    return LJ::trim( substr( $text, 0, $cur ) );
 }
 
 # <LJFUNC>
--------------------------------------------------------------------------------