Only interpolate action tag content when defined.
[matthijs/upstream/blosxom-plugins.git] / general / interpolate_fancy
index 4f5b6ebc3ec01d201a416e57ec77bb9a45871fef..9eaf045219c4fef24b400a5630130ebddb2d9471 100644 (file)
@@ -109,8 +109,8 @@ sub do_interpolate {
     # Halt recursive interpolation of story $body
     # by mangling interpolation tags (to be unmangled in a moment)
     unless ($recurse_into_story) {
-      $blosxom::title =~ s/<(\@|\??\$)/<#INTERPOLATE_FANCY_DEFANG#$1/gsi;
-      $blosxom::body =~ s/<(\@|\??\$)/<#INTERPOLATE_FANCY_DEFANG#$1/gsi;
+      $blosxom::title =~ s/<(\@|\??\$)/<#INTERPOLATE_FANCY_DEFANG#$1/gsi if defined $blosxom::title;
+      $blosxom::body =~ s/<(\@|\??\$)/<#INTERPOLATE_FANCY_DEFANG#$1/gsi if defined $blosxom::body;
     }
 
     my $template = shift;
@@ -134,7 +134,7 @@ sub do_interpolate {
     # Variable expansion (unconditional, recursive)
     #
     # e.g. <$var />
-    while( $template =~ s/<\$([a-zA-Z?]\w+(?:::\w+)*)\s+?\/>/"defined \$$1 ? \$$1 : undef"/gsee ) { }
+    while( $template =~ s/<\$([a-zA-Z?]\w+(?:::\w+)*)\s+?\/>/"defined \$$1 ? \$$1 : ''"/gsee ) { }
 
     #
     # Actions 
@@ -155,6 +155,11 @@ sub do_interpolate {
 
 sub _test {
   my($variable, $attr) = @_;
+  # If the variable is not defined, treat it as the empty string in
+  # comparisons below
+  if (!defined $variable) { 
+    $variable = '';
+  }
   my $attributes = interpolate_fancy::_attributes($attr);
 
   defined $attributes->{eq} and return $variable eq $attributes->{eq};
@@ -171,7 +176,9 @@ sub _action {
   my($plugin, $action, $attr, $content) = @_;
   my $result;
 
-  $content =~ s#<\@((?:\w|::)+?)\.(\w+?)\s+?(.+?)?(?:>(.*?)<\/\@\1\.\2>|\s+?\/>)#&interpolate_fancy::_action($1,$2,$3,$4)#gse;
+  if (defined $content) {
+    $content =~ s#<\@((?:\w|::)+?)\.(\w+?)\s+?(.+?)?(?:>(.*?)<\/\@\1\.\2>|\s+?\/>)#&interpolate_fancy::_action($1,$2,$3,$4)#gse;
+  }
 
   my $attributes = interpolate_fancy::_attributes($attr);