1
2
3
ÄÖÜẞ
<a href="//" title="ÄÖÜẞ">ÄÖÜẞ</a>
<img src="/a.jpg" alt="ÄÖÜẞ">
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#! /opt/perls/perls/perl-5.38.2/bin/perl use strict; use warnings; use 5.038; use utf8; use CGI::Carp qw( fatalsToBrowser ); use CGI; use HTML::Restrict; my $html = do { local $/; <DATA> }; my $cgi = CGI->new(); my $hr = HTML::Restrict->new( rules => { a => [ qw( href title ) ], img => [ qw( src alt ) ], }); my $processed = $hr->process($html); binmode(STDOUT,':utf8'); say $cgi->header({ -type => 'text/html', -charset => 'UTF-8', }), $processed; __DATA__ ÄÖÜẞ <a href="//" title="ÄÖÜẞ">ÄÖÜẞ</a> <img src="/a.jpg" alt="ÄÖÜẞ">
2024-12-31T08:15:03 rostiFür die Strings die den Funktionen in HTML::Entities übergeben werden muß die Zeichenkodierung eingeschaltet sein. Sonst Müll.
1 2 3 4 5 6 7 8 9 10 11
use strict; use warnings; use HTML::Entities; use Encode; my $html = qq(<img alt="Weißer Nebel" />); # Übergebe Bytes # print encode_entities($html), "\n"; # Müll # Schalte UTF-8-Kodierung ein print encode_entities(decode_utf8($html)); # Korrekt
1
2
3
4
5
$string = Encode::decode_utf8($string);
$string = $tf->process($string); # HTML::Restrict filter
$string = Encode::encode_utf8($string)