Only mangle $blosxom::title and body if defined.
[matthijs/upstream/blosxom-plugins.git] / general / interpolate_fancy
index 2c79e8ea1c4525c6c3ad78da0afca1e519fdce7f..45208d24d77feec491916c5cbce68f8144aee2bf 100644 (file)
@@ -8,6 +8,9 @@
 
 package interpolate_fancy;
 
+use warnings;
+use strict;
+
 # --- Configurable variables -----
 
 # Do you want me to recursively interpolate into the story $title
@@ -106,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;
@@ -131,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 
@@ -152,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};