mirror of
https://github.com/parsecsv/parsecsv-for-php.git
synced 2026-02-19 08:36:39 +00:00
Prevent quoting of sinlge-column file. Needed because auto() with...
...single-column file will not set field delimiter. This commit is a bug fix. For a test see testSaveWithDefaultSettings.
This commit is contained in:
@@ -980,19 +980,18 @@ class parseCSV {
|
|||||||
* Enclose values if needed
|
* Enclose values if needed
|
||||||
* - only used by unparse()
|
* - only used by unparse()
|
||||||
*
|
*
|
||||||
* @param string $value Cell value to process
|
* @param string $value Cell value to process
|
||||||
* @param string|null $delimiter
|
* @param string $delimiter Character to put between fields
|
||||||
*
|
*
|
||||||
* @return string Processed value
|
* @return string Processed value
|
||||||
*/
|
*/
|
||||||
protected function _enclose_value($value = null, $delimiter = null) {
|
protected function _enclose_value($value = null, $delimiter) {
|
||||||
if (is_null($delimiter)) {
|
|
||||||
$delimiter = $this->delimiter;
|
|
||||||
}
|
|
||||||
if ($value !== null && $value != '') {
|
if ($value !== null && $value != '') {
|
||||||
$delimiter_quoted = preg_quote($delimiter, '/');
|
$delimiter_quoted = $delimiter ?
|
||||||
|
preg_quote($delimiter, '/') . "|"
|
||||||
|
: '';
|
||||||
$enclosure_quoted = preg_quote($this->enclosure, '/');
|
$enclosure_quoted = preg_quote($this->enclosure, '/');
|
||||||
$pattern = "/" . $delimiter_quoted . "|" . $enclosure_quoted . "|\n|\r/i";
|
$pattern = "/" . $delimiter_quoted . $enclosure_quoted . "|\n|\r/i";
|
||||||
if ($this->enclose_all || preg_match($pattern, $value) || ($value{0} == ' ' || substr($value, -1) == ' ')) {
|
if ($this->enclose_all || preg_match($pattern, $value) || ($value{0} == ' ' || substr($value, -1) == ' ')) {
|
||||||
$value = str_replace($this->enclosure, $this->enclosure . $this->enclosure, $value);
|
$value = str_replace($this->enclosure, $this->enclosure . $this->enclosure, $value);
|
||||||
$value = $this->enclosure . $value . $this->enclosure;
|
$value = $this->enclosure . $value . $this->enclosure;
|
||||||
|
|||||||
Reference in New Issue
Block a user