summaryrefslogtreecommitdiff
path: root/ext/standard/file.c
diff options
context:
space:
mode:
authorAdam Harvey <aharvey@php.net>2013-01-15 17:33:54 +0800
committerAdam Harvey <aharvey@php.net>2013-01-15 17:33:54 +0800
commitc077074c1379b5faed386106fdbb53f5d17fd6e7 (patch)
tree237cd6d4ed2208d403ca3ab38e84c438ee87a22d /ext/standard/file.c
parent9b5cb0e8059b1e8bec096067491ed8d75f878938 (diff)
downloadphp-git-c077074c1379b5faed386106fdbb53f5d17fd6e7.tar.gz
Revert "Update fputcsv() to escape all characters equally."
On second thoughts, while the behaviour _is_ broken, this isn't the right fix. This reverts commit 9b5cb0e8059b1e8bec096067491ed8d75f878938.
Diffstat (limited to 'ext/standard/file.c')
-rw-r--r--ext/standard/file.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/ext/standard/file.c b/ext/standard/file.c
index fa85bf1b3a..8b18155cf8 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -1953,6 +1953,7 @@ PHP_FUNCTION(fputcsv)
{
char delimiter = ','; /* allow this to be set as parameter */
char enclosure = '"'; /* allow this to be set as parameter */
+ const char escape_char = '\\';
php_stream *stream;
int ret;
zval *fp = NULL, *fields = NULL, **field_tmp = NULL, field;
@@ -2007,19 +2008,24 @@ PHP_FUNCTION(fputcsv)
/* enclose a field that contains a delimiter, an enclosure character, or a newline */
if (FPUTCSV_FLD_CHK(delimiter) ||
FPUTCSV_FLD_CHK(enclosure) ||
+ FPUTCSV_FLD_CHK(escape_char) ||
FPUTCSV_FLD_CHK('\n') ||
FPUTCSV_FLD_CHK('\r') ||
FPUTCSV_FLD_CHK('\t') ||
- FPUTCSV_FLD_CHK('\\') ||
FPUTCSV_FLD_CHK(' ')
) {
char *ch = Z_STRVAL(field);
char *end = ch + Z_STRLEN(field);
+ int escaped = 0;
smart_str_appendc(&csvline, enclosure);
while (ch < end) {
- if (*ch == enclosure) {
+ if (*ch == escape_char) {
+ escaped = 1;
+ } else if (!escaped && *ch == enclosure) {
smart_str_appendc(&csvline, enclosure);
+ } else {
+ escaped = 0;
}
smart_str_appendc(&csvline, *ch);
ch++;