From 305ef8c333a9d0b376dfe6d4a34fcd97195eccdd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppi...@redhat.com>
Date: Fri, 30 Sep 2016 10:36:38 +0200
Subject: Fix Encode::encode_utf8(undef) to return undef

---
 ...-return-value-of-Encode-encode_utf8-undef.patch | 73 ++++++++++++++++++++++
 perl-Encode.spec                                   |  9 ++-
 2 files changed, 81 insertions(+), 1 deletion(-)
 create mode 100644 
Encode-2.86-Fix-return-value-of-Encode-encode_utf8-undef.patch

diff --git a/Encode-2.86-Fix-return-value-of-Encode-encode_utf8-undef.patch 
b/Encode-2.86-Fix-return-value-of-Encode-encode_utf8-undef.patch
new file mode 100644
index 0000000..fb48e8e
--- /dev/null
+++ b/Encode-2.86-Fix-return-value-of-Encode-encode_utf8-undef.patch
@@ -0,0 +1,73 @@
+From 646aaae364fc8cd19786a66b88ec6aaf3f093024 Mon Sep 17 00:00:00 2001
+From: Pali <p...@cpan.org>
+Date: Thu, 11 Aug 2016 23:09:26 +0200
+Subject: [PATCH] Fix return value of Encode::encode_utf8(undef)
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Documentation says that '$octets = encode_utf8($string)' is equivalent to
+'$octets = encode("utf8", $string)'. And if the $string is undef, then
+undef is returned. However without this patch encode_utf8(undef) returned
+'' (empty string) and not undef. This patch fixes it and undef is returned.
+
+All other utf8 Encode calls already returns undef, just encode_utf8() acted
+differently.
+
+  Encode::encode('utf8', undef) -> undef
+  Encode::decode('utf8', undef) -> undef
+  Encode::decode_utf8(undef) -> undef
+
+Reported bug: https://rt.cpan.org/Public/Bug/Display.html?id=116904
+
+Signed-off-by: Petr Písař <ppi...@redhat.com>
+---
+ Encode.pm   |  1 +
+ t/utf8ref.t | 15 ++++++++++++++-
+ 2 files changed, 15 insertions(+), 1 deletion(-)
+
+diff --git a/Encode.pm b/Encode.pm
+index bda8e1b..bc600be 100644
+--- a/Encode.pm
++++ b/Encode.pm
+@@ -254,6 +254,7 @@ sub from_to($$$;$) {
+ 
+ sub encode_utf8($) {
+     my ($str) = @_;
++    return undef unless defined $str;
+     utf8::encode($str);
+     return $str;
+ }
+diff --git a/t/utf8ref.t b/t/utf8ref.t
+index 3253e08..aff098f 100644
+--- a/t/utf8ref.t
++++ b/t/utf8ref.t
+@@ -6,7 +6,7 @@ use strict;
+ use warnings;
+ use Encode;
+ use Test::More;
+-plan tests => 4;
++plan tests => 12;
+ #plan 'no_plan';
+ 
+ # my $a = find_encoding('ASCII');
+@@ -18,3 +18,16 @@ is $u->encode($r), '';
+ $r = {};
+ is decode_utf8($r), ''.$r;
+ is $u->decode($r), '';
++use warnings 'uninitialized';
++
++is encode_utf8(undef), undef;
++is decode_utf8(undef), undef;
++
++is encode_utf8(''), '';
++is decode_utf8(''), '';
++
++is Encode::encode('utf8', undef), undef;
++is Encode::decode('utf8', undef), undef;
++
++is Encode::encode('utf8', ''), '';
++is Encode::decode('utf8', ''), '';
+-- 
+2.7.4
+
diff --git a/perl-Encode.spec b/perl-Encode.spec
index 91b3342..feca9d2 100644
--- a/perl-Encode.spec
+++ b/perl-Encode.spec
@@ -8,7 +8,7 @@ Version:        %{cpan_version}
 # perl-encoding sub-package has independent version which does not change
 # often and consecutive builds would clash on perl-encoding NEVRA. This is the
 # same case as in perl.spec.
-Release:        10%{?dist}
+Release:        11%{?dist}
 Summary:        Character encodings in Perl
 # ucm:          UCD
 # bin/encguess: Artistic 2.0
@@ -19,6 +19,9 @@ URL:            http://search.cpan.org/dist/Encode/
 Source0:        
http://www.cpan.org/authors/id/D/DA/DANKOGAI/Encode-%{cpan_version}.tar.gz
 #Avoid loading optional modules from default . (CVE-2016-1238)
 Patch0:         
Encode-2.84-CVE-2016-1238-avoid-loading-optional-modules-from.patch
+# Fix Encode::encode_utf8(undef) to return undef, CPAN RT#116904,
+# in upstream after 2.86
+Patch1:         Encode-2.86-Fix-return-value-of-Encode-encode_utf8-undef.patch
 BuildRequires:  coreutils
 BuildRequires:  findutils
 BuildRequires:  make
@@ -131,6 +134,7 @@ your own encoding to perl. No knowledge of XS is necessary.
 %prep
 %setup -q -n Encode-%{cpan_version}
 %patch0 -p1
+%patch1 -p1
 
 %build
 # Additional scripts can be installed by appending MORE_SCRIPTS, UCM files by
@@ -172,6 +176,9 @@ make test
 %{perl_vendorarch}/Encode/encode.h
 
 %changelog
+* Fri Sep 30 2016 Petr Pisar <ppi...@redhat.com> - 3:2.84-11
+- Fix Encode::encode_utf8(undef) to return undef (CPAN RT#116904)
+
 * Fri Sep 16 2016 Petr Pisar <ppi...@redhat.com> - 3:2.84-10
 - Add Artistic 2.0 into license tag because of encguess tool
 
-- 
cgit v0.12


        
http://pkgs.fedoraproject.org/cgit/perl-Encode.git/commit/?h=f24&id=305ef8c333a9d0b376dfe6d4a34fcd97195eccdd
_______________________________________________
perl-devel mailing list -- perl-devel@lists.fedoraproject.org
To unsubscribe send an email to perl-devel-le...@lists.fedoraproject.org

Reply via email to