Skip to content

Commit 86c196b

Browse files
committed
Fix GH-7980: Unexpected result for iconv_mime_decode
We need to reset the shift state right after conversion, to cater to potenially following plain encodings. Also, there is no need to reset the shift for plain encodings, because these are not state-dependent. Closes GH-8025.
1 parent bea542a commit 86c196b

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ PHP NEWS
77

88
- Iconv:
99
. Fixed bug GH-7953 (ob_clean() only does not set Content-Encoding). (cmb)
10+
. Fixed bug GH-7980 (Unexpected result for iconv_mime_decode). (cmb)
1011

1112
- Zlib:
1213
. Fixed bug GH-7953 (ob_clean() only does not set Content-Encoding). (cmb)

ext/iconv/iconv.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,9 @@ static php_iconv_err_t _php_iconv_mime_decode(smart_str *pretval, const char *st
15761576
}
15771577

15781578
err = _php_iconv_appendl(pretval, ZSTR_VAL(decoded_text), ZSTR_LEN(decoded_text), cd);
1579+
if (err == PHP_ICONV_ERR_SUCCESS) {
1580+
err = _php_iconv_appendl(pretval, NULL, 0, cd);
1581+
}
15791582
zend_string_release_ex(decoded_text, 0);
15801583

15811584
if (err != PHP_ICONV_ERR_SUCCESS) {
@@ -1716,13 +1719,6 @@ static php_iconv_err_t _php_iconv_mime_decode(smart_str *pretval, const char *st
17161719
*next_pos = p1;
17171720
}
17181721

1719-
if (cd != (iconv_t)(-1)) {
1720-
_php_iconv_appendl(pretval, NULL, 0, cd);
1721-
}
1722-
if (cd_pl != (iconv_t)(-1)) {
1723-
_php_iconv_appendl(pretval, NULL, 0, cd_pl);
1724-
}
1725-
17261722
smart_str_0(pretval);
17271723
out:
17281724
if (cd != (iconv_t)(-1)) {

ext/iconv/tests/gh7980.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
Bug GH-7980 (Unexpected result for iconv_mime_decode)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("iconv")) die("skip iconv extension not available");
6+
?>
7+
--FILE--
8+
<?php
9+
$subject = '=?windows-1258?Q?DSI_Charg=E9_de_Formation_Jean_Dupont?= <[email protected]>';
10+
var_dump(iconv_mime_decode($subject, ICONV_MIME_DECODE_STRICT, 'UTF-8'));
11+
?>
12+
--EXPECT--
13+
string(57) "DSI Chargé de Formation Jean Dupont <[email protected]>"

0 commit comments

Comments
 (0)