aboutsummaryrefslogtreecommitdiffstats
path: root/Rpmdrake
diff options
context:
space:
mode:
authorThierry Vignaud <tv@mandriva.org>2008-02-12 09:40:47 +0000
committerThierry Vignaud <tv@mandriva.org>2008-02-12 09:40:47 +0000
commit60d2c62eada3cf15226503bff9dd7c909e897128 (patch)
treec3655c9e63f00d94b93825a55229129f7cffa3f8 /Rpmdrake
parent6ba17da2ed0430eea39cab733daf3403e613bf08 (diff)
downloadrpmdrake-60d2c62eada3cf15226503bff9dd7c909e897128.tar
rpmdrake-60d2c62eada3cf15226503bff9dd7c909e897128.tar.gz
rpmdrake-60d2c62eada3cf15226503bff9dd7c909e897128.tar.bz2
rpmdrake-60d2c62eada3cf15226503bff9dd7c909e897128.tar.xz
rpmdrake-60d2c62eada3cf15226503bff9dd7c909e897128.zip
(ensure_utf8) introduce it (copied & slightly altered from rpmtools)
so that we never crash on garbaged UTF-8
Diffstat (limited to 'Rpmdrake')
-rw-r--r--Rpmdrake/formatting.pm14
1 files changed, 14 insertions, 0 deletions
diff --git a/Rpmdrake/formatting.pm b/Rpmdrake/formatting.pm
index bf8aa987..8b1ab479 100644
--- a/Rpmdrake/formatting.pm
+++ b/Rpmdrake/formatting.pm
@@ -35,6 +35,7 @@ use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(
$spacing
+ ensure_utf8
format_changelog_changelogs
format_changelog_string
format_field
@@ -50,6 +51,19 @@ our @EXPORT = qw(
urpm_name);
+# from rpmtools, #37482:
+sub ensure_utf8 {
+ my ($s) = @_;
+ require Encode;
+ Encode::_utf8_on($s); #- this is done on the copy
+ if (!Encode::is_utf8($s, 1)) {
+ Encode::_utf8_off($_[0]);
+ Encode::from_to($_[0], 'iso-8859-15', 'utf8'); # most probable
+ }
+ Encode::_utf8_on($_[0]); #- now we know it is valid utf8
+ $_[0];
+}
+
sub rpm_description {
my ($description) = @_;
utf8::decode($description);