Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/Template/Filters.pm
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,9 @@ sub url_filter {
#------------------------------------------------------------------------
# html_filter() [% FILTER html %]
#
# Convert any '<', '>' or '&' characters to the HTML equivalents, '&lt;',
# '&gt;' and '&amp;', respectively.
# Convert any '<', '>', '&', '"' or "'" characters to the HTML
# equivalents, '&lt;', '&gt;', '&amp;', '&quot;' and '&#39;',
# respectively.
#------------------------------------------------------------------------

sub html_filter {
Expand All @@ -308,6 +309,7 @@ sub html_filter {
s/</&lt;/g;
s/>/&gt;/g;
s/"/&quot;/g;
s/'/&#39;/g;
}
return $text;
}
Expand All @@ -316,8 +318,8 @@ sub html_filter {
#------------------------------------------------------------------------
# xml_filter() [% FILTER xml %]
#
# Same as the html filter, but adds the conversion of ' to &apos; which
# is native to XML.
# Same as the html filter, but uses &apos; for single quotes (the XML
# named entity) instead of &#39; (the numeric reference used for HTML).
#------------------------------------------------------------------------

sub xml_filter {
Expand Down
1 change: 1 addition & 0 deletions lib/Template/Plugin/HTML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ sub escape {
s/</&lt;/g;
s/>/&gt;/g;
s/"/&quot;/g;
s/'/&#39;/g;
}
$text;
}
Expand Down
8 changes: 7 additions & 1 deletion t/filter.t
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,13 @@ The &lt;cat&gt; sat on the &lt;mat&gt;
"It isn't what I expected", he replied.
[% END %]
-- expect --
&quot;It isn't what I expected&quot;, he replied.
&quot;It isn&#39;t what I expected&quot;, he replied.

-- test --
-- name html filter single-quoted attributes --
[% val = "it's <dangerous> & \"broken\""; val FILTER html %]
-- expect --
it&#39;s &lt;dangerous&gt; &amp; &quot;broken&quot;

-- test --
[% FILTER xml %]
Expand Down
7 changes: 7 additions & 0 deletions t/html.t
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ my%20file.html
-- expect --
if (a &lt; b &amp;&amp; c &gt; d) ...

-- test --
-- name escape single quotes --
[% USE HTML -%]
[% HTML.escape("it's a <tag attr='val'>test") %]
-- expect --
it&#39;s a &lt;tag attr=&#39;val&#39;&gt;test

-- test --
-- name sorted --
[% USE HTML(sorted=1) -%]
Expand Down
2 changes: 1 addition & 1 deletion t/vmethods/text.t
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ Tim O'Reilly said \"Oh really?\"
-- name text.html --
[% markup.html %]
-- expect --
a &lt; b &gt; &amp; c &quot;d&quot; 'e'
a &lt; b &gt; &amp; c &quot;d&quot; &#39;e&#39;

-- test --
-- name text.xml --
Expand Down