summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2011-05-29 10:23:06 +0000
committerIlia Alshanetsky <iliaa@php.net>2011-05-29 10:23:06 +0000
commit34de2c30c5499519eab42575b0ed489fb5865a99 (patch)
treeb4c9b2ce7e411e5eba4e577fa4034d6aa9605901
parentd2b11712ff9156a87291457fd29a9c0d3bc348b4 (diff)
downloadphp-git-34de2c30c5499519eab42575b0ed489fb5865a99.tar.gz
Fixed bug #53848 (fgetcsv() ignores spaces at beginnings of fields).
-rw-r--r--ext/standard/file.c28
-rw-r--r--ext/standard/tests/file/bug53848.phpt25
2 files changed, 33 insertions, 20 deletions
diff --git a/ext/standard/file.c b/ext/standard/file.c
index 527f12df61..868fbab4da 100644
--- a/ext/standard/file.c
+++ b/ext/standard/file.c
@@ -2098,29 +2098,17 @@ PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, char
tptr = temp;
- /* 1. Strip any leading space */
- for (;;) {
- inc_len = (bptr < limit ? (*bptr == '\0' ? 1: php_mblen(bptr, limit - bptr)): 0);
- switch (inc_len) {
- case -2:
- case -1:
- inc_len = 1;
- php_ignore_value(php_mblen(NULL, 0));
- break;
- case 0:
- goto quit_loop_1;
- case 1:
- if (!isspace((int)*(unsigned char *)bptr) || *bptr == delimiter) {
- goto quit_loop_1;
- }
- break;
- default:
- goto quit_loop_1;
+ inc_len = (bptr < limit ? (*bptr == '\0' ? 1: php_mblen(bptr, limit - bptr)): 0);
+ if (inc_len == 1) {
+ char *tmp = bptr;
+ while (isspace((int)*(unsigned char *)tmp)) {
+ tmp++;
+ }
+ if (*tmp == enclosure) {
+ bptr = tmp;
}
- bptr += inc_len;
}
- quit_loop_1:
if (first_field && bptr == line_end) {
add_next_index_null(return_value);
break;
diff --git a/ext/standard/tests/file/bug53848.phpt b/ext/standard/tests/file/bug53848.phpt
new file mode 100644
index 0000000000..016d59d0ca
--- /dev/null
+++ b/ext/standard/tests/file/bug53848.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Bug #53848 (fgetcsv removes leading spaces from fields)
+--FILE--
+<?php
+$file = dirname(__FILE__) . "/bug39538.csv";
+@unlink($file);
+file_put_contents($file, "a,b\n c, d");
+$fp = fopen($file, "r");
+while ($l = fgetcsv($fp)) var_dump($l);
+fclose($fp);
+@unlink($file);
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ string(1) "a"
+ [1]=>
+ string(1) "b"
+}
+array(2) {
+ [0]=>
+ string(3) " c"
+ [1]=>
+ string(3) " d"
+}