From: Christoph M. Becker Date: Thu, 21 Jul 2016 16:36:12 +0000 (+0200) Subject: Fix #72330: CSV fields incorrectly split if escape char followed by UTF chars X-Git-Tag: php-7.0.10RC1~67^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f2c2a4be9e466f14677089efe33e20ca0b146809;p=php Fix #72330: CSV fields incorrectly split if escape char followed by UTF chars We must not forget to properly reset the state for multibyte characters following an escape character. --- diff --git a/NEWS b/NEWS index fb08c0213e..c2cae0af64 100644 --- a/NEWS +++ b/NEWS @@ -44,6 +44,10 @@ PHP NEWS . Fixed bug #72222 (ReflectionClass::export doesn't handle array constants). (Nikita Nefedov) +- Standard: + . Fixed bug #72330 (CSV fields incorrectly split if escape char followed by + UTF chars). (cmb) + - SPL: . Fixed bug #72122 (IteratorIterator breaks '@' error suppression). (kinglozzer) diff --git a/ext/standard/file.c b/ext/standard/file.c index f8c4e0450b..d8471fff1c 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -2219,6 +2219,7 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, char memcpy(tptr, hunk_begin, bptr - hunk_begin); tptr += (bptr - hunk_begin); hunk_begin = bptr; + state = 0; break; default: bptr += inc_len; diff --git a/ext/standard/tests/file/bug72330.phpt b/ext/standard/tests/file/bug72330.phpt new file mode 100644 index 0000000000..843032ae2d --- /dev/null +++ b/ext/standard/tests/file/bug72330.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #72330 (CSV fields incorrectly split if escape char followed by UTF chars) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +array(2) { + [0]=> + string(11) "first #с؀" + [1]=> + string(6) "second" +}