Skip to content

Commit

Permalink
Fix stray joiner which showed up while appending empty value to text.
Browse files Browse the repository at this point in the history
  • Loading branch information
racke committed Jul 2, 2015
1 parent 808551f commit 6027969
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/Template/Flute/HTML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,9 @@ sub _elt_indicate_replacements {
$elt->{"flute_$name"}->{rep_sub} = sub {
my ($elt, $str) = @_;
$str ||= '';
$elt->set_text($elt->{"flute_$name"}->{rep_text_orig} . $joiner . $str);
if (! $joiner || $str =~ /\S/) {
$elt->set_text($elt->{"flute_$name"}->{rep_text_orig} . $joiner . $str);
}
};
}
elsif ($sob->{op} eq 'toggle' && exists $sob->{args}
Expand Down
18 changes: 17 additions & 1 deletion t/values/append.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use strict;
use warnings;

use Test::More tests => 6;
use Test::More tests => 7;
use Template::Flute;

my ($spec, $html, $flute, $out);
Expand Down Expand Up @@ -45,6 +45,22 @@ $out = $flute->process;
like ($out, qr%<div class="test">FOO&amp;BAR</div>%,
"value with op=append and joiner=&");

# simple append with joiner without value
$spec = q{<specification>
<value name="test" op="append" joiner="&amp;"/>
</specification>
};

$flute = Template::Flute->new(template => $html,
specification => $spec,
values => {test => ''},
);

$out = $flute->process;

like ($out, qr%<div class="test">FOO</div>%,
"value with op=append, joiner=& and empty value");

# simple append with joiner which doesn't escape
$spec = q{<specification>
<value name="test" op="append" joiner="|"/>
Expand Down

0 comments on commit 6027969

Please sign in to comment.