HTML.uri() muss Strings zuerst von Perls internem Encoding nach UTF-8 wandeln
authorMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 10 May 2011 14:05:38 +0000 (16:05 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 10 May 2011 14:05:38 +0000 (16:05 +0200)
Fix für Bug 1641.

SL/Dispatcher.pm
SL/Template/Plugin/HTMLFixes.pm [new file with mode: 0644]

index 909433e..c1f31a4 100644 (file)
@@ -19,6 +19,7 @@ use SL::Locale;
 use SL::Common;
 use SL::Form;
 use SL::Helper::DateTime;
+use SL::Template::Plugin::HTMLFixes;
 use List::Util qw(first);
 use File::Basename;
 
diff --git a/SL/Template/Plugin/HTMLFixes.pm b/SL/Template/Plugin/HTMLFixes.pm
new file mode 100644 (file)
index 0000000..3f328a8
--- /dev/null
@@ -0,0 +1,29 @@
+package SL::Template::Plugin::HTMLFixes;
+
+use Template::Plugin::HTML;
+
+1;
+
+package Template::Plugin::HTML;
+
+use strict;
+
+use Encode;
+
+# Replacement for Template::Plugin::HTML::url.
+
+# Strings in Lx-Office are stored in Perl's internal encoding but have
+# to be output as UTF-8. A normal regex replace doesn't do that
+# creating invalid UTF-8 characters upon URL-unescaping.
+
+# The only addition is the "Encode::encode()" line.
+
+sub url {
+    my ($self, $text) = @_;
+    return undef unless defined $text;
+    $text =  Encode::encode('utf-8-strict', $text) if $::locale && $::locale->is_utf8;
+    $text =~ s/([^a-zA-Z0-9_.-])/uc sprintf("%%%02x",ord($1))/eg;
+    return $text;
+}
+
+1;