Skip Menu |

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

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

People
Owner: Nobody in particular
Requestors: frantisek [...] netsafe.cz
Cc:
AdminCc:

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



Subject: Characters not escaped properly in Template::Plugin::URL
Date: Wed, 20 Nov 2013 14:17:36 +0100
To: bug-Template-Toolkit [...] rt.cpan.org
From: František Svoboda <frantisek [...] netsafe.cz>
The URL plugin doesn't escape utf-8 characters properly for use in URL causing an error when trying to decode them later. How to reproduce: - in template, use URL module: [% USE url %] - in same template, employ this code to generate a link: <a href="[% url('test', var='???') %]">test</a> - click on the link generated by above code - on perl 5.14.4 built for i686-linux (Linux dev 3.2.0-4-686-pae #1 SMP Debian 3.2.41-2+deb7u2 i686 GNU/Linux) this causes: Generic Exception: utf8 "\x91" does not map to Unicode at /opt/perl-5.14.4/lib/5.14.4/i686-linux/Encode.pm line 215. The characters in var are not correctly escaped for use in URl. Using utf8 (use utf8) does not help. How to fix: - use URI::Escape in the URL.pm module; - alter escape() function so: sub escape { my $toencode = shift; return uri_escape_utf8($toencode); }
Subject: [rt.cpan.org #90545] Comment on escaping UTF-8 URL characters
Date: Thu, 16 Oct 2014 00:17:32 +0300
To: bug-template-toolkit [...] rt.cpan.org
From: Ruslan Batdalov <linnando [...] yandex.ru>
The bug is described by František correctly, but the proposed solution is not ideal, I'm afraid. There is no need to use an external module. uri_escape_utf8 differs from uri_escape only in calling utf8::encode before escaping, and uri_escape does virtually the same thing as Template::Plugin::URL does now. So, it's enough to utf8::encode the string in sub escape to solve the bug. But it is mentioned in the URI::Escape docs that this solution leads to a different encoding of characters in the 128..255 range. Still correct, but different. AFAIU, that's why they created function uri_escape_utf8 instead of patching uri_escape. If it is a problem (for me it isn't), it may make sense to create a separate TT plugin for UTF8-encoded urls too.
Ticket migrated to github as https://github.com/abw/Template2/issues/163