5c62078292c4d6170484a45fd445b117d9a6d713
[kivitendo-erp.git] / SL / Template / Plugin / HTMLFixes.pm
1 package SL::Template::Plugin::HTMLFixes;
2
3 use Template::Plugin::HTML;
4
5 1;
6
7 package Template::Plugin::HTML;
8
9 use strict;
10
11 use Encode;
12
13 # Replacement for Template::Plugin::HTML::url.
14
15 # Strings in kivitendo are stored in Perl's internal encoding but have
16 # to be output as UTF-8. A normal regex replace doesn't do that
17 # creating invalid UTF-8 characters upon URL-unescaping.
18
19 # The only addition is the "Encode::encode()" line.
20 no warnings 'redefine';
21 sub url {
22     my ($self, $text) = @_;
23     return undef unless defined $text;
24     $text =  Encode::encode('utf-8-strict', $text) if $::locale && $::locale->is_utf8;
25     $text =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg;
26     return $text;
27 }
28
29 1;