Skip to content

Commit b3d67b5

Browse files
authored
[PHP 8.4] fgetcsv() - The $escape parameter must be provided as its default value will change (OpenMage#4297)
* fgetcsv - lib/Varien/Convert/Parser/Csv.php Deprecated. The $escape parameter must be provided as its default value will change. * fgetcsv - app/code/core/Mage/ImportExport/Model/Import/Adapter/Csv.php Deprecated. The $escape parameter must be provided as its default value will change. * fgetcsv - lib/Varien/Io/File.php Deprecated. The $escape parameter must be provided as its default value will change. * fgetcsv - lib/Varien/File/Csv.php Deprecated. The $escape parameter must be provided as its default value will change. * fgetcsv - app/code/core/Mage/Dataflow/Model/Session/Parser/Csv.php Deprecated. The $escape parameter must be provided as its default value will change. * Missing variabile fEsc in function parseTest() * Missing $ in front of the variable * Revert the typo * escape parameter in function * PHP CS Fixer for lib/Varien/Io/File.php
1 parent d34be82 commit b3d67b5

File tree

5 files changed

+20
-9
lines changed

5 files changed

+20
-9
lines changed

app/code/core/Mage/Dataflow/Model/Session/Parser/Csv.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function parse()
2525
{
2626
$fDel = $this->getVar('delimiter', ',');
2727
$fEnc = $this->getVar('enclose', '"');
28+
$fEsc = $this->getVar('escape', '\\');
2829

2930
if ($fDel == '\\t') {
3031
$fDel = "\t";
@@ -41,7 +42,7 @@ public function parse()
4142
$sessionId = Mage::registry('current_dataflow_session_id');
4243
$import = Mage::getModel('dataflow/import');
4344
$map = new Varien_Convert_Mapper_Column();
44-
for ($i = 0; $line = fgetcsv($fp, 4096, $fDel, $fEnc); $i++) {
45+
for ($i = 0; $line = fgetcsv($fp, 4096, $fDel, $fEnc, $fEsc); $i++) {
4546
if ($i == 0) {
4647
if ($this->getVar('fieldnames')) {
4748
$fields = $line;

app/code/core/Mage/ImportExport/Model/Import/Adapter/Csv.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ class Mage_ImportExport_Model_Import_Adapter_Csv extends Mage_ImportExport_Model
3535
*/
3636
protected $_enclosure = '"';
3737

38+
/**
39+
* Field escape character.
40+
*
41+
* @var string
42+
*/
43+
protected $_escape = '\\';
44+
3845
/**
3946
* Source file handler.
4047
*
@@ -72,7 +79,7 @@ protected function _init()
7279
#[\ReturnTypeWillChange]
7380
public function next()
7481
{
75-
$this->_currentRow = fgetcsv($this->_fileHandler, null, $this->_delimiter, $this->_enclosure);
82+
$this->_currentRow = fgetcsv($this->_fileHandler, null, $this->_delimiter, $this->_enclosure, $this->_escape);
7683
$this->_currentKey = $this->_currentRow ? $this->_currentKey + 1 : null;
7784
}
7885

@@ -86,8 +93,8 @@ public function rewind()
8693
{
8794
// rewind resource, reset column names, read first row as current
8895
rewind($this->_fileHandler);
89-
$this->_colNames = fgetcsv($this->_fileHandler, null, $this->_delimiter, $this->_enclosure);
90-
$this->_currentRow = fgetcsv($this->_fileHandler, null, $this->_delimiter, $this->_enclosure);
96+
$this->_colNames = fgetcsv($this->_fileHandler, null, $this->_delimiter, $this->_enclosure, $this->_escape);
97+
$this->_currentRow = fgetcsv($this->_fileHandler, null, $this->_delimiter, $this->_enclosure, $this->_escape);
9198

9299
if ($this->_currentRow) {
93100
$this->_currentKey = 0;
@@ -112,7 +119,7 @@ public function seek($position)
112119
if ($position < $this->_currentKey) {
113120
$this->rewind();
114121
}
115-
while ($this->_currentRow = fgetcsv($this->_fileHandler, null, $this->_delimiter, $this->_enclosure)) {
122+
while ($this->_currentRow = fgetcsv($this->_fileHandler, null, $this->_delimiter, $this->_enclosure, $this->_escape)) {
116123
if (++$this->_currentKey == $position) {
117124
return;
118125
}

lib/Varien/Convert/Parser/Csv.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public function parse()
2525
{
2626
$fDel = $this->getVar('delimiter', ',');
2727
$fEnc = $this->getVar('enclose', '"');
28+
$fEsc = $this->getVar('escape', '\\');
2829

2930
if ($fDel == '\\t') {
3031
$fDel = "\t";
@@ -38,7 +39,7 @@ public function parse()
3839
fseek($fp, 0);
3940

4041
$data = [];
41-
for ($i = 0; $line = fgetcsv($fp, 4096, $fDel, $fEnc); $i++) {
42+
for ($i = 0; $line = fgetcsv($fp, 4096, $fDel, $fEnc, $fEsc); $i++) {
4243
if (0 == $i) {
4344
if ($this->getVar('fieldnames')) {
4445
$fields = $line;
@@ -65,6 +66,7 @@ public function parseTest()
6566
{
6667
$fDel = $this->getVar('delimiter', ',');
6768
$fEnc = $this->getVar('enclose', '"');
69+
$fEsc = $this->getVar('escape', '\\');
6870

6971
if ($fDel == '\\t') {
7072
$fDel = "\t";
@@ -81,7 +83,7 @@ public function parseTest()
8183
$sessionId = Mage::registry('current_dataflow_session_id');
8284
$import = Mage::getModel('dataflow/import');
8385
$map = new Varien_Convert_Mapper_Column();
84-
for ($i = 0; $line = fgetcsv($fp, 4096, $fDel, $fEnc); $i++) {
86+
for ($i = 0; $line = fgetcsv($fp, 4096, $fDel, $fEnc, $fEsc); $i++) {
8587
if (0 == $i) {
8688
if ($this->getVar('fieldnames')) {
8789
$fields = $line;

lib/Varien/File/Csv.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Varien_File_Csv
2222
protected $_lineLength = 0;
2323
protected $_delimiter = ',';
2424
protected $_enclosure = '"';
25+
protected $_escape = '\\';
2526

2627
public function __construct()
2728
{
@@ -77,7 +78,7 @@ public function getData($file)
7778
}
7879

7980
$fh = fopen($file, 'r');
80-
while ($rowData = fgetcsv($fh, $this->_lineLength, $this->_delimiter, $this->_enclosure)) {
81+
while ($rowData = fgetcsv($fh, $this->_lineLength, $this->_delimiter, $this->_enclosure, $this->_escape)) {
8182
$data[] = $rowData;
8283
}
8384
fclose($fh);

lib/Varien/Io/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public function streamWriteCsv(array $row, $delimiter = ',', $enclosure = '"')
242242
return false;
243243
}
244244

245-
return @fputcsv($this->_streamHandler, $row, $delimiter, $enclosure);
245+
return @fputcsv($this->_streamHandler, $row, $delimiter, $enclosure, '\\');
246246
}
247247

248248
/**

0 commit comments

Comments
 (0)