]> granicus.if.org Git - php/commitdiff
Fix for bug #48289 (iconv_mime_encode() quoted-printable scheme is broken).
authorAdam Harvey <aharvey@php.net>
Tue, 4 May 2010 11:56:59 +0000 (11:56 +0000)
committerAdam Harvey <aharvey@php.net>
Tue, 4 May 2010 11:56:59 +0000 (11:56 +0000)
Thanks to Hiroaki Kawai for the original patch.

NEWS
ext/iconv/iconv.c
ext/iconv/tests/bug48289.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 7b9a08b6e4e9c00b10a281aeaaddac90e63e84cb..221532c884c91d1ba4cc1bed840bdf245216e14e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -66,6 +66,8 @@ PHP                                                                        NEWS
 - Fixed bug #49723 (LimitIterator with empty SeekableIterator). (Etienne)
 - Fixed bug #49576 (FILTER_VALIDATE_EMAIL filter needs updating) (Rasmus)
 - Fixed bug #49267 (Linking fails for iconv). (Moriyosh)
+- Fixed bug #48289 (iconv_mime_encode() quoted-printable scheme is broken).
+  (Adam, patch from hiroaki dot kawai at gmail dot com).
 - Fixed bug #43314 (iconv_mime_encode(), broken Q scheme). (Rasmus)
 - Fixed bug #23229 (syslog() truncates messages). (Adam)
 
index 755426242f85a51567ca0d1870888d7459c7239d..b70c3df210d9e417edfc71a92b348c418c0a759d 100644 (file)
@@ -1217,7 +1217,7 @@ static php_iconv_err_t _php_iconv_mime_encode(smart_str *pretval, const char *fn
                                prev_in_left = ini_in_left = in_left;
                                ini_in_p = in_p;
 
-                               for (out_size = char_cnt; out_size > 0;) {
+                               for (out_size = (char_cnt - 2) / 3; out_size > 0;) {
                                        size_t prev_out_left;
 
                                        nbytes_required = 0;
diff --git a/ext/iconv/tests/bug48289.phpt b/ext/iconv/tests/bug48289.phpt
new file mode 100644 (file)
index 0000000..fc2cd36
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+Bug #48289 (iconv_mime_encode() quoted-printable scheme is broken)
+--SKIPIF--
+<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?>
+--FILE--
+<?php
+$text = "\xE3\x83\x86\xE3\x82\xB9\xE3\x83\x88\xE3\x83\x86\xE3\x82\xB9\xE3\x83\x88";
+$options = array(
+    'scheme' => 'Q',
+    'input-charset' => 'UTF-8',
+    'output-charset' => 'UTF-8',
+    'line-length' => 30,
+);
+
+echo iconv_mime_encode('Subject', $text, $options);
+--EXPECT--
+Subject: =?UTF-8?Q?=E3=83=86?=
+ =?UTF-8?Q?=E3=82=B9?=
+ =?UTF-8?Q?=E3=83=88?=
+ =?UTF-8?Q?=E3=83=86?=
+ =?UTF-8?Q?=E3=82=B9?=
+ =?UTF-8?Q?=E3=83=88?=