Skip Menu |

This queue is for tickets about the Template-Toolkit CPAN distribution.

Report information
The Basics
Id: 101193
Status: resolved
Priority: 0/
Queue: Template-Toolkit

People
Owner: Nobody in particular
Requestors: themanchicken [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: HTML.escape() double-escapes already-escaped entities
Date: Mon, 29 Dec 2014 13:59:21 -0500
To: bug-Template-Toolkit [...] rt.cpan.org
From: Michael Stemle <themanchicken [...] gmail.com>
If you use the code: [% HTML.escape( "&gt;tag&lt;" ) %] then it will expand to: &amp;gt;tag&amp;lt; which is different from the expected behavior of leaving existing escaped entities alone. I recommend changing the regexp for ampersand to be this instead: s/&(?![a-zA-Z0-9#-]+;)/&amp;/g This uses a negative look-ahead assertion to only match entities which are not already encoded. Please let me know if you have any questions. ​ -- ~ Michael D. Stemle, Jr.
On 2014-12-29 13:59:50, themanchicken@gmail.com wrote: Show quoted text
> If you use the code: > > [% HTML.escape( "&gt;tag&lt;" ) %] > > then it will expand to: > > &amp;gt;tag&amp;lt; > > which is different from the expected behavior of leaving existing escaped > entities alone. > > I recommend changing the regexp for ampersand to be this instead: > > s/&(?![a-zA-Z0-9#-]+;)/&amp;/g > > This uses a negative look-ahead assertion to only match entities which are > not already encoded.
I think the current behavior is right. The input/output relation of HTML.escape is text -> html, not possibly_partial_html -> html. And other CPAN modules like CGI.pm also behave like TT: $ perl -MCGI -e 'warn CGI::escapeHTML("&gt;tag&lt;")' &amp;gt;tag&amp;lt; at -e line 1. If you think you need such a function, then you can always create an own Template-Toolkit plugin.
Ticket migrated to github as https://github.com/abw/Template2/issues/169