From ce39e2e22bbdc4f403fbc77b95cecca0250974f9 Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Mon, 21 Apr 2025 09:16:40 +0900 Subject: [PATCH 1/2] Added a test --- ext/standard/tests/file/gh18348.phpt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 ext/standard/tests/file/gh18348.phpt diff --git a/ext/standard/tests/file/gh18348.phpt b/ext/standard/tests/file/gh18348.phpt new file mode 100644 index 0000000000000..2a75b265372b5 --- /dev/null +++ b/ext/standard/tests/file/gh18348.phpt @@ -0,0 +1,18 @@ +--TEST-- +GH-18348 (fputcsv incorrectly escapes when quote char is both enclosure and escape char) +--FILE-- + +--EXPECT-- +"J""a""n" +"He said ""Hello""" +"Line1\Line2" From 5b65e2c313744f03c92ed6ca05444e9e6a0087cf Mon Sep 17 00:00:00 2001 From: Saki Takamachi Date: Mon, 21 Apr 2025 09:20:18 +0900 Subject: [PATCH 2/2] Removed the conditional branch for escape_char. --- ext/standard/file.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/ext/standard/file.c b/ext/standard/file.c index 5936766dac863..c42b92e0ebe1a 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -1788,16 +1788,11 @@ PHPAPI ssize_t php_fputcsv(php_stream *stream, zval *fields, char delimiter, cha ) { char *ch = ZSTR_VAL(field_str); char *end = ch + ZSTR_LEN(field_str); - int escaped = 0; smart_str_appendc(&csvline, enclosure); while (ch < end) { - if (escape_char != PHP_CSV_NO_ESCAPE && *ch == escape_char) { - escaped = 1; - } else if (!escaped && *ch == enclosure) { + if (*ch == enclosure) { smart_str_appendc(&csvline, enclosure); - } else { - escaped = 0; } smart_str_appendc(&csvline, *ch); ch++;