Skip to content

Loading…

Fixed printing 'ARRAY' on multiline token #11

Merged
merged 1 commit into from

2 participants

@ypresto

I'm sorry but I made big bug on multiline with previous pull-req.
Something like below will cause bad text "ARRAY(0xfoobar)" to be printed.

multiline |
%start_of_block_after_multiline
    ...
@vti vti merged commit cd516de into vti:master
@ypresto ypresto deleted the ypresto:fix_multiline_spec branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 10, 2012
  1. @ypresto
This page is out of date. Refresh to see the latest.
Showing with 35 additions and 9 deletions.
  1. +5 −8 lib/Text/Haml.pm
  2. +30 −1 t/multiline.t
View
13 lib/Text/Haml.pm
@@ -248,6 +248,7 @@ sub parse {
my $tape = $self->tape;
my $level;
+ my @multiline_el_queue;
my @lines = split /\n/, $tmpl;
push @lines, '' if $tmpl =~ m/\n$/;
@lines = ('') if $tmpl eq "\n";
@@ -501,6 +502,7 @@ sub parse {
$el->{line} ||= $line . "$1|"; # XXX: is this really necessary?
push @$tape, $el;
+ push @multiline_el_queue, $el;
}
# Continue concatenation
@@ -513,20 +515,15 @@ sub parse {
# Normal text
else {
- # Terminate multiline tokens before current token
- if ($tape->[-1] && ref $tape->[-1]->{text} eq 'ARRAY') {
- $tape->[-1]->{text} = join(" ", @{$tape->[-1]->{text}});
- }
-
$el->{text} = $line if $line;
push @$tape, $el;
}
}
- # Terminate multiline tokens on the end of file
- if ($tape->[-1] && ref $tape->[-1]->{text} eq 'ARRAY') {
- $tape->[-1]->{text} = join(" ", @{$tape->[-1]->{text}});
+ # Finalize multilines
+ for my $el (@multiline_el_queue) {
+ $el->{text} = join(" ", @{$el->{text}});
}
}
View
31 t/multiline.t
@@ -5,7 +5,7 @@ use warnings;
use Text::Haml;
-use Test::More tests => 2;
+use Test::More tests => 4;
my $haml = Text::Haml->new;
@@ -43,3 +43,32 @@ is($output, <<'EOF');
<p>This is short.</p>
</whoo>
EOF
+
+$output = $haml->render(<<'EOF');
+%body
+ test
+ Wow.|
+ - my $bar = 17;
+ test2
+EOF
+is($output, <<'EOF');
+<body>
+ test
+ Wow.
+ test2
+</body>
+EOF
+
+$output = $haml->render(<<'EOF');
+%body
+ this is
+ a test for |
+ multiline token |
+ on last line. |
+EOF
+is($output, <<'EOF');
+<body>
+ this is
+ a test for multiline token on last line.
+</body>
+EOF
Something went wrong with that request. Please try again.