Index: branches/release-35/lib/MT/Template/ContextHandlers.pm
===================================================================
--- branches/release-35/lib/MT/Template/ContextHandlers.pm (revision 1911)
+++ branches/release-35/lib/MT/Template/ContextHandlers.pm (revision 1926)
@@ -1324,5 +1324,4 @@
     my $vars = $ctx->{__stash}{vars} ||= {};
     my $glue = $args->{glue};
-    $glue = '' unless defined $glue;
     my $var = $args->{var};
     for (my $i = $start; $i <= $end; $i += $incr) {
@@ -1336,9 +1335,8 @@
         my $res = $builder->build($ctx, $tokens, $cond);
         return $ctx->error($builder->errstr) unless defined $res;
-        if ($res ne '') {
-            $out .= $glue if $cnt > 1;
-            $out .= $res;
-            $cnt++;
-        }
+        $out .= $glue
+            if defined $glue && $cnt > 1 && length($out) && length($res);
+        $out .= $res;
+        $cnt++;
     }
     return $out;
@@ -1590,5 +1588,4 @@
     my $vars = $ctx->{__stash}{vars} ||= {};
     my $glue = $args->{glue};
-    $glue = '' unless defined $glue;
     foreach my $item (@$var) {
         local $vars->{__first__} = $i == 1;
@@ -1625,5 +1622,5 @@
         return $ctx->error($builder->errstr) unless defined $res;
         if ($res ne '') {
-            $out .= $glue if $i > 1;
+            $out .= $glue if defined $glue && $i > 1 && length($out) && length($res);
             $out .= $res;
             $i++;
@@ -1916,5 +1913,5 @@
     my $tokens = $ctx->stash('tokens');
     my $needs_entries = (($ctx->stash('uncompiled') || '') =~ /<MT:?Entries/i) ? 1 : 0;
-    my $glue = $args->{glue} || '';
+    my $glue = $args->{glue};
     my $res = '';
     local $ctx->{__stash}{all_tag_count} = undef;
@@ -1974,5 +1971,5 @@
         defined(my $out = $builder->build($ctx, $tokens, $cond))
             or return $ctx->error( $builder->errstr );
-        $res .= $glue if $res ne '';
+        $res .= $glue if defined $glue && length($res) && length($out);
         $res .= $out;
     }
@@ -2097,5 +2094,5 @@
     my $entry = $ctx->stash('entry');
     return '' unless $entry;
-    my $glue = $args->{glue} || '';
+    my $glue = $args->{glue};
 
     local $ctx->{__stash}{tag_max_count} = undef;
@@ -2113,5 +2110,5 @@
         defined(my $out = $builder->build($ctx, $tokens, $cond))
             or return $ctx->error( $builder->errstr );
-        $res .= $glue if $res ne '';
+        $res .= $glue if defined $glue && length($res) && length($out);
         $res .= $out;
     }
@@ -4229,5 +4226,5 @@
         return $ctx->error( $builder->errstr ) unless defined $out;
         $last_day = $this_day;
-        $res .= $glue if defined $glue && $i;
+        $res .= $glue if defined $glue && $i && length($res) && length($out);
         $res .= $out;
         $i++;
@@ -4739,13 +4736,14 @@
     my $builder = $ctx->stash('builder');
     my $tokens = $ctx->stash('tokens');
-    my @res;
+    my $res;
+    my $glue = $args->{glue};
     for my $cat (@$cats) {
         local $ctx->{__stash}->{category} = $cat;
         defined(my $out = $builder->build($ctx, $tokens, $cond))
             or return $ctx->error( $builder->errstr );
-        push @res, $out if $out ne '';
-    }
-    my $sep = $args->{glue} || '';
-    join $sep, @res;
+        $res .= $glue if defined $glue && length($res) && length($out);
+        $res .= $out;
+    }
+    $res;
 }
 
@@ -6314,5 +6312,5 @@
     my $builder = $ctx->stash('builder');
     my $tokens = $ctx->stash('tokens');
-    my $glue = exists $args->{glue} ? $args->{glue} : '';
+    my $glue = $args->{glue};
     ## In order for this handler to double as the handler for
     ## <MTArchiveList archive_type="Category">, it needs to support
@@ -6356,5 +6354,5 @@
               ArchiveListFooter => $last }))
             or return $ctx->error( $builder->errstr );
-        $res .= $glue if $res ne '';
+        $res .= $glue if defined $glue && length($res) && length($out);
         $res .= $out;
         $cat = $next_cat;
@@ -6637,5 +6635,6 @@
     my $builder = $ctx->stash('builder');
     my $tokens = $ctx->stash('tokens');
-    my @res;
+    my $res;
+    my $glue = $args->{glue};
     for my $cat (@$cats) {
         next if $e->category && ($cat->label eq $e->category->label);
@@ -6643,8 +6642,8 @@
         defined(my $out = $builder->build($ctx, $tokens, $cond))
             or return $ctx->error( $builder->errstr );
-        push @res, $out;
-    }
-    my $sep = $args->{glue} || '';
-    join $sep, @res; 
+        $res .= $glue if defined $glue && length($res) && length($out);
+        $res .= $out if length($out);
+    }
+    $res;
 }
 
@@ -7189,5 +7188,5 @@
     # Get the arguments
     my $exclude_current = $args->{'exclude_current'};
-    my $glue = $args->{'glue'} || '';
+    my $glue = $args->{'glue'};
 
     # Get the current category
@@ -7196,5 +7195,5 @@
     return '' if ($cat eq '');
 
-    my @res;
+    my $res;
 
     # Put together the list of parent categories
@@ -7211,9 +7210,8 @@
             $out = 'cat-' . $c->id;
         }
-        push @res, $out;
-    }
-
-    # Slap them all together with some glue
-    return join $glue, @res;
+        $res .= $glue if defined $glue && length($res) && length($out);
+        $res .= $out if length($out);
+    }
+    $res;
 }
 
@@ -7922,5 +7920,5 @@
     my $asset = $ctx->stash('asset');
     return '' unless $asset;
-    my $glue = $args->{glue} || '';
+    my $glue = $args->{glue};
 
     local $ctx->{__stash}{tag_max_count} = undef;
@@ -7943,5 +7941,5 @@
         defined(my $out = $builder->build($ctx, $tokens, $cond))
             or return $ctx->error( $builder->errstr );
-        $res .= $glue if $res ne '';
+        $res .= $glue if defined $glue && length($res) && length($out);
         $res .= $out;
     }
@@ -8850,5 +8848,4 @@
 
     my $glue = $args->{glue};
-    $glue = q() unless defined $glue;
 
     my $output = q();
@@ -8868,5 +8865,5 @@
             }
             )) or return $ctx->error( $build->errstr );
-        $output .= $glue if $i > 1;
+        $output .= $glue if defined $glue && $i > 1 && length($output) && length($out);
         $output .= $out;
     }
