afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)
afuna ([personal profile] afuna) wrote in [site community profile] changelog2010-01-17 04:38 pm

[dw-free] Prohibit Conditional Declarations (backend cleanup)

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

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

Cleanup, to proactively defend against future issues. See bug for details

Patch by [personal profile] kareila.

Files modified:
  • bin/maint/synsuck.pl
  • bin/worker/incoming-email
  • cgi-bin/Apache/SendStats.pm
  • cgi-bin/DW/Logic/UserLinkBar.pm
  • cgi-bin/DW/Pay.pm
  • cgi-bin/DW/Shop/Cart.pm
  • cgi-bin/DW/Worker/ContentImporter/LiveJournal.pm
  • cgi-bin/DW/Worker/ContentImporter/LiveJournal/Comments.pm
  • cgi-bin/DW/Worker/ContentImporter/Local/Comments.pm
  • cgi-bin/DW/Worker/ContentImporter/Local/Entries.pm
  • cgi-bin/JSON/Converter.pm
--------------------------------------------------------------------------------
diff -r ea171f7eb151 -r c86af8486f8b bin/maint/synsuck.pl
--- a/bin/maint/synsuck.pl	Tue Jan 12 14:07:27 2010 -0600
+++ b/bin/maint/synsuck.pl	Sun Jan 17 16:35:40 2010 +0000
@@ -34,7 +34,7 @@ use LJ::SynSuck;
         # need to get some more rows
         my $dbh = LJ::get_db_writer();
         my $current_jobs = join(",", map { $dbh->quote($_->[0]) } values %child_jobs);
-        my $in_sql = " AND u.userid NOT IN ($current_jobs)" if $current_jobs;
+        my $in_sql = $current_jobs ? " AND u.userid NOT IN ($current_jobs)" : "";
         my $sth = $dbh->prepare("SELECT u.user, s.userid, s.synurl, s.lastmod, " .
                                 "       s.etag, s.numreaders, s.checknext " .
                                 "FROM user u, syndicated s " .
diff -r ea171f7eb151 -r c86af8486f8b bin/worker/incoming-email
--- a/bin/worker/incoming-email	Tue Jan 12 14:07:27 2010 -0600
+++ b/bin/worker/incoming-email	Sun Jan 17 16:35:40 2010 +0000
@@ -304,15 +304,15 @@ EMAIL_END
 
     # convert email body to utf-8
     my $content_type = $head->get('Content-type:');
-    my $charset      = $1
-      if $content_type =~ /\bcharset=[\'\"]?(\S+?)[\'\"]?[\s\;]/i;
-    if (   defined($charset)
-        && $charset !~ /^UTF-?8$/i
-        && Unicode::MapUTF8::utf8_supported_charset($charset) )
-    {
-        $body =
-          Unicode::MapUTF8::to_utf8(
-            { -string => $body, -charset => $charset } );
+    if ( $content_type =~ /\bcharset=[\'\"]?(\S+?)[\'\"]?[\s\;]/i ) {
+        my $charset = $1;
+        if ( defined $charset
+             && $charset !~ /^UTF-?8$/i
+             && Unicode::MapUTF8::utf8_supported_charset( $charset )
+           ) {
+            $body = Unicode::MapUTF8::to_utf8(
+                    { -string => $body, -charset => $charset } );
+        }
     }
 
     my $spid = LJ::Support::file_request(
diff -r ea171f7eb151 -r c86af8486f8b cgi-bin/Apache/SendStats.pm
--- a/cgi-bin/Apache/SendStats.pm	Tue Jan 12 14:07:27 2010 -0600
+++ b/cgi-bin/Apache/SendStats.pm	Sun Jan 17 16:35:40 2010 +0000
@@ -32,7 +32,7 @@ sub handler
     return OK if $r->main;
     return OK unless $LJ::HAVE_AVAIL && $LJ::FREECHILDREN_BCAST;
 
-    my $callback = $r->current_callback() if $r;
+    my $callback = $r ? $r->current_callback() : "";
     my $cleanup = $callback eq "PerlCleanupHandler";
     my $childinit = $callback eq "PerlChildInitHandler";
 
diff -r ea171f7eb151 -r c86af8486f8b cgi-bin/DW/Logic/UserLinkBar.pm
--- a/cgi-bin/DW/Logic/UserLinkBar.pm	Tue Jan 12 14:07:27 2010 -0600
+++ b/cgi-bin/DW/Logic/UserLinkBar.pm	Sun Jan 17 16:35:40 2010 +0000
@@ -94,7 +94,7 @@ sub get_links {
     
     my @ret;
     foreach my $key ( @link_keyseq ) {
-        my $link = $self->$key if $self->can( $key );
+        my $link = $self->can( $key ) ? $self->$key : undef;
         push @ret, $link if $link;
     }
     return @ret;
diff -r ea171f7eb151 -r c86af8486f8b cgi-bin/DW/Pay.pm
--- a/cgi-bin/DW/Pay.pm	Tue Jan 12 14:07:27 2010 -0600
+++ b/cgi-bin/DW/Pay.pm	Sun Jan 17 16:35:40 2010 +0000
@@ -110,8 +110,9 @@ sub get_paid_status {
     DW::Pay::clear_error();
 
     my $uuid = shift;
+    my $uid;
 
-    my $uid = LJ::want_userid($uuid) if defined $uuid;
+    $uid = LJ::want_userid( $uuid ) if defined $uuid;
     return error( ERR_FATAL, "Invalid user object/userid passed in." )
         unless defined $uid && $uid > 0;
 
diff -r ea171f7eb151 -r c86af8486f8b cgi-bin/DW/Shop/Cart.pm
--- a/cgi-bin/DW/Shop/Cart.pm	Tue Jan 12 14:07:27 2010 -0600
+++ b/cgi-bin/DW/Shop/Cart.pm	Sun Jan 17 16:35:40 2010 +0000
@@ -101,8 +101,9 @@ sub get_from_cartid {
 # returns a new cart given an ordernum
 sub get_from_ordernum {
     my ( $class, $ordernum ) = @_;
+    my ( $cartid, $authcode );
 
-    my ( $cartid, $authcode ) = ( $1+0, $2 )
+    ( $cartid, $authcode ) = ( $1+0, $2 )
         if $ordernum =~ /^(\d+)-(.+)$/;
     return undef
         unless $cartid && $cartid > 0;
@@ -197,8 +198,11 @@ sub get_all {
     my ( $class, $u, %opts ) = @_;
     $u = LJ::want_user( $u );
 
-    my $extra_sql = " AND state NOT IN ($DW::Shop::STATE_OPEN, $DW::Shop::STATE_CLOSED, $DW::Shop::STATE_CHECKOUT)"
-        if $opts{finished};
+    my $extra_sql = $opts{finished}
+                    ? " AND state NOT IN ($DW::Shop::STATE_OPEN," .
+                      " $DW::Shop::STATE_CLOSED," .
+                      " $DW::Shop::STATE_CHECKOUT)"
+                    : "";
 
     my $dbh = LJ::get_db_writer()
         or return undef;
diff -r ea171f7eb151 -r c86af8486f8b cgi-bin/DW/Worker/ContentImporter/LiveJournal.pm
--- a/cgi-bin/DW/Worker/ContentImporter/LiveJournal.pm	Tue Jan 12 14:07:27 2010 -0600
+++ b/cgi-bin/DW/Worker/ContentImporter/LiveJournal.pm	Sun Jan 17 16:35:40 2010 +0000
@@ -209,21 +209,22 @@ sub remap_username_friend {
         my $r = $ua->get( "http://$data->{hostname}/tools/opml.bml?user=$username" );
         my $data = $r->content;
 
-        my $url = $1
-            if $data =~ m!<ownerName>(.+?)</ownerName>!;
-        $url = "http://$url/"
-            unless $url =~ m/^https?:/;
-        return undef unless $url;
+        if ( $data =~ m!<ownerName>(.+?)</ownerName>! ) {
+            my $url = $1;
+            $url = "http://$url/"
+                unless $url =~ m/^https?:/;
+            return undef unless $url;
 
-        if ( $url =~ m!http://(.+)\.$LJ::DOMAIN\/$! ) {
-            # this appears to be a local user!
-            # Map this to the local userid in feed_map too, as this is a local user.
-            return LJ::User->new_from_url( $url )->id;
+            if ( $url =~ m!http://(.+)\.$LJ::DOMAIN\/$! ) {
+                # this appears to be a local user!
+                # Map this to the local userid in feed_map too, as this is a local user.
+                return LJ::User->new_from_url( $url )->id;
+            }
+
+            my $iu = LJ::User::load_identity_user( 'O', $url, undef )
+                or return undef;
+            return $iu->id;
         }
-
-        my $iu = LJ::User::load_identity_user( 'O', $url, undef )
-            or return undef;
-        return $iu->id;
 
     } else {
         my $url_prefix = "http://$data->{hostname}/~" . $username;
diff -r ea171f7eb151 -r c86af8486f8b cgi-bin/DW/Worker/ContentImporter/LiveJournal/Comments.pm
--- a/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Comments.pm	Tue Jan 12 14:07:27 2010 -0600
+++ b/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Comments.pm	Sun Jan 17 16:35:40 2010 +0000
@@ -116,10 +116,11 @@ sub try_work {
                     ( $turl =~ /\b$data->{username}\b/ ||
                         ( $data->{usejournal} && $turl =~ /\b$data->{usejournal}\b/ ) );
 
-        my $jitemid = $1 >> 8
-            if $url =~ m!/(\d+)\.html$!;
-        $jitemid_map->{$jitemid} = $entry_map->{$url};
-        $entry_source->{$jitemid_map->{$jitemid}} = $url;
+        if ( $url =~ m!/(\d+)\.html$! ) {
+            my $jitemid = $1 >> 8;
+            $jitemid_map->{$jitemid} = $entry_map->{$url};
+            $entry_source->{$jitemid_map->{$jitemid}} = $url;
+        }
     }
     $log->( 'Entry map has %d entries post-prune.', scalar( keys %$entry_map ) );
 
@@ -143,9 +144,10 @@ sub try_work {
                     ( $turl =~ /\b$data->{username}\b/ ||
                         ( $data->{usejournal} && $turl =~ /\b$data->{usejournal}\b/ ) );
 
-        my $jtalkid = $1 >> 8
-            if $url =~ m!thread=(\d+)$!;
-        $jtalkid_map->{$jtalkid} = $talk_map->{$url};
+        if ( $url =~ m!thread=(\d+)$! ) {
+            my $jtalkid = $1 >> 8;
+            $jtalkid_map->{$jtalkid} = $talk_map->{$url};
+        }
     }
 
     # parameters for below
diff -r ea171f7eb151 -r c86af8486f8b cgi-bin/DW/Worker/ContentImporter/Local/Comments.pm
--- a/cgi-bin/DW/Worker/ContentImporter/Local/Comments.pm	Tue Jan 12 14:07:27 2010 -0600
+++ b/cgi-bin/DW/Worker/ContentImporter/Local/Comments.pm	Sun Jan 17 16:35:40 2010 +0000
@@ -104,8 +104,7 @@ sub insert_comment {
     # load the data we need to make this comment
     my $jitem = LJ::Entry->new( $u, jitemid => $cmt->{jitemid} );
     my $source = ( $cmt->{entry_source} || $jitem->prop( "import_source" ) ) . "?thread=" . ( $cmt->{id} << 8 );
-    my $user = LJ::load_userid( $cmt->{posterid} )
-        if $cmt->{posterid};
+    my $user = $cmt->{posterid} ? LJ::load_userid( $cmt->{posterid} ) : undef;
 
     # fix the XML timestamp to a useful timestamp
     my $date = $cmt->{date};
diff -r ea171f7eb151 -r c86af8486f8b cgi-bin/DW/Worker/ContentImporter/Local/Entries.pm
--- a/cgi-bin/DW/Worker/ContentImporter/Local/Entries.pm	Tue Jan 12 14:07:27 2010 -0600
+++ b/cgi-bin/DW/Worker/ContentImporter/Local/Entries.pm	Sun Jan 17 16:35:40 2010 +0000
@@ -90,7 +90,8 @@ sub post_event {
 
     return if $map->{$evt->{key}};
 
-    my ( $yr, $month, $day, $hr, $min, $sec ) = ( $1, $2, $3, $4, $5, $6 )
+    my ( $yr, $month, $day, $hr, $min, $sec );
+    ( $yr, $month, $day, $hr, $min, $sec ) = ( $1, $2, $3, $4, $5, $6 )
         if $evt->{eventtime} =~ m/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/;
 
     my %proto = (
diff -r ea171f7eb151 -r c86af8486f8b cgi-bin/JSON/Converter.pm
--- a/cgi-bin/JSON/Converter.pm	Tue Jan 12 14:07:27 2010 -0600
+++ b/cgi-bin/JSON/Converter.pm	Sun Jan 17 16:35:40 2010 +0000
@@ -58,10 +58,11 @@ sub hashToJson {
 sub hashToJson {
 	my $self = shift;
 	my $obj  = shift;
-	my ($k,$v);
-	my %res;
+	my ( $k, $v );
+	my ( $pre, $post, %res );
 
-	my ($pre,$post) = $self->_upIndent() if($self->{pretty});
+	( $pre, $post ) = $self->_upIndent()
+	    if $self->{pretty};
 
 	if(grep { $_ == $obj } @{ $self->{_stack_myself} }){
 		die "circle ref!";
@@ -102,9 +103,10 @@ sub arrayToJson {
 sub arrayToJson {
 	my $self = shift;
 	my $obj  = shift;
-	my @res;
+	my ( $pre, $post, @res );
 
-	my ($pre,$post) = $self->_upIndent() if($self->{pretty});
+	( $pre, $post ) = $self->_upIndent()
+	    if $self->{pretty};
 
 	if(grep { $_ == $obj } @{ $self->{_stack_myself} }){
 		die "circle ref!";
@@ -190,7 +192,9 @@ sub _stringfy {
 
 sub _initConvert {
 	my $self = shift;
-	my %opt  = %{ $_[0] } if(@_ > 0 and ref($_[0]) eq 'HASH');
+	my %opt;
+	%opt = %{ $_[0] }
+	    if ( @_ > 0 and ref $_[0] eq 'HASH' );
 
 	$self->{autoconv}    = $JSON::AUTOCONVERT if(!defined $self->{autoconv});
 	$self->{execcoderef} = $JSON::ExecCoderef if(!defined $self->{execcoderef});
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org