Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made escaping default behavior

  • Loading branch information...
commit bd889c88fc8eb2518daf20b955882291e8d59c80 1 parent 4f1ba80
@vti authored
View
22 lib/Text/Haml.pm
@@ -251,6 +251,7 @@ sub parse {
# Doctype
if ($line =~ m/^!!!(?: ([^ ]+)(?: (.*))?)?$/) {
$el->{type} = 'text';
+ $el->{escape} = 0;
$el->{text} = $self->_doctype($1, $2);
push @$tape, $el;
next;
@@ -541,6 +542,12 @@ EOF
}
}
+ my $escape = '';
+ if ((!exists $el->{escape} && $self->escape_html) || (exists
+ $el->{escape} && $el->{escape} == 1)) {
+ $escape = 'escape';
+ }
+
if ($el->{line} && $prev_el && $prev_el->{level} >= $el->{level}) {
while (my $poped = pop @$stack) {
my $poped_offset = ' ' x $poped->{level};
@@ -632,9 +639,10 @@ EOF
$output .= qq| . "</$el->{name}>"|;
}
elsif ($el->{text}) {
- $output
- .= '."' . $self->_parse_text($el->{text}) . '"';
- $output .= qq|. "</$el->{name}>"| unless $el->{autoclose};
+ $output .= qq/. $escape / . '"'
+ . $self->_parse_text($el->{text}) . '";';
+ $output .= qq|\$_H .= "</$el->{name}>"|
+ unless $el->{autoclose};
}
elsif (
!$self->tape->[$count + 1]
@@ -657,17 +665,11 @@ EOF
$el->{text} = '' unless defined $el->{text};
if ($el->{expr}) {
- my $escape = '';
- if ((!exists $el->{escape} && $self->escape_html) || (exists
- $el->{escape} && $el->{escape} == 1)) {
- $escape = 'escape';
- }
-
$output .= qq/. $escape / . +$el->{text};
$output .= qq/;\$_H .= "\n"/;
}
elsif ($el->{text}) {
- $output .= '."' . $self->_parse_text($el->{text}) . '"';
+ $output .= '.'.qq/$escape /.'"' . $self->_parse_text($el->{text}) . '"';
$output .= qq/. "\n"/;
}
View
8 t/comments.t
@@ -25,15 +25,15 @@ EOF
$output = $haml->render(<<'EOF');
/
- %p This doesn't render...
+ %p This does not render...
%div
- %h1 Because it's commented out!
+ %h1 Because it is commented out!
EOF
is($output, <<'EOF');
<!--
- <p>This doesn't render...</p>
+ <p>This does not render...</p>
<div>
- <h1>Because it's commented out!</h1>
+ <h1>Because it is commented out!</h1>
</div>
-->
EOF
View
6 t/complete.t
@@ -58,8 +58,8 @@ is($output, <<'EOF');
</li>
<li>
The first character of any line is called
- the "control character" - it says "make a tag"
- or "run Ruby code" or all sorts of things.
+ the &quot;control character&quot; - it says &quot;make a tag&quot;
+ or &quot;run Ruby code&quot; or all sorts of things.
</li>
<li>
Text::Haml takes care of nicely indenting your HTML.
@@ -79,7 +79,7 @@ is($output, <<'EOF');
</div>
<div class='note'>
<p>
- This example doesn't allow Ruby to be executed,
+ This example doesn&apos;t allow Ruby to be executed,
but real Text::Haml does.
</p>
<p>
View
16 t/html-escaping.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use Test::More tests => 2;
+use Test::More tests => 4;
use Text::Haml;
@@ -21,6 +21,20 @@ EOF
$haml->escape_html(1);
$output = $haml->render(<<'EOF');
+1 > 2
+EOF
+is($output, <<'EOF');
+1 &gt; 2
+EOF
+
+$output = $haml->render(<<'EOF');
+%foo 1 > 2
+EOF
+is($output, <<'EOF');
+<foo>1 &gt; 2</foo>
+EOF
+
+$output = $haml->render(<<'EOF');
&= "I like cheese & crackers"
EOF
is($output, <<'EOF');
View
8 t/multiline.t
@@ -14,13 +14,13 @@ my $output = $haml->render(<<'EOF');
%hoo I think this might get |
pretty long so I should |
probably make it |
- multiline so it doesn't |
+ multiline so it does not |
look awful.
%p This is short.
EOF
is($output, <<'EOF');
<whoo>
- <hoo>I think this might get pretty long so I should probably make it multiline so it doesn't look awful.</hoo>
+ <hoo>I think this might get pretty long so I should probably make it multiline so it does not look awful.</hoo>
<p>This is short.</p>
</whoo>
EOF
@@ -31,14 +31,14 @@ $output = $haml->render(<<'EOF');
I think this might get |
pretty long so I should |
probably make it |
- multiline so it doesn't |
+ multiline so it does not |
look awful.
%p This is short.
EOF
is($output, <<'EOF');
<whoo>
<hoo>
- I think this might get pretty long so I should probably make it multiline so it doesn't look awful.
+ I think this might get pretty long so I should probably make it multiline so it does not look awful.
</hoo>
<p>This is short.</p>
</whoo>
View
1  t/plain.t
@@ -29,6 +29,7 @@ is($output, <<'EOF');
</gee>
EOF
+$haml->escape_html(0);
$output = $haml->render(<<'EOF');
%p
<div id="blah">Blah!</div>
Please sign in to comment.
Something went wrong with that request. Please try again.