diff --git a/src/Csv.php b/src/Csv.php index ccdd9c5..6d8920c 100644 --- a/src/Csv.php +++ b/src/Csv.php @@ -1137,7 +1137,7 @@ class Csv { : ''; $enclosure_quoted = preg_quote($this->enclosure, '/'); $pattern = "/" . $delimiter_quoted . $enclosure_quoted . "|\n|\r/i"; - if ($this->enclose_all || preg_match($pattern, $value) || (strpos($value, ' ') === 0 || substr($value, -1) == ' ')) { + if ($this->enclose_all || preg_match($pattern, $value) || strpos($value, ' ') === 0 || substr($value, -1) == ' ') { $value = str_replace($this->enclosure, $this->enclosure . $this->enclosure, $value); $value = $this->enclosure . $value . $this->enclosure; } diff --git a/tests/methods/ObjectThatHasToStringMethod.php b/tests/methods/ObjectThatHasToStringMethod.php new file mode 100644 index 0000000..ebda6cd --- /dev/null +++ b/tests/methods/ObjectThatHasToStringMethod.php @@ -0,0 +1,13 @@ +unparseAndCompare($expected); } + public function testObjectCells() { + $this->csv->data = [ + [ + 'column1' => new ObjectThatHasToStringMethod(), + 'column2' => 'boring', + ], + ]; + $this->csv->linefeed = "\n"; + $expected = "column1,column2\nsome value,boring\n"; + $this->unparseAndCompare($expected); + } + private function unparseAndCompare($expected, $fields = array()) { $str = $this->csv->unparse($this->csv->data, $fields); $this->assertEquals($expected, $str);