diff --git a/admin/tool/brickfield/classes/local/htmlchecker/brickfield_accessibility_guideline.php b/admin/tool/brickfield/classes/local/htmlchecker/brickfield_accessibility_guideline.php index 7cbdd1ebe11..68fe68f5c5e 100644 --- a/admin/tool/brickfield/classes/local/htmlchecker/brickfield_accessibility_guideline.php +++ b/admin/tool/brickfield/classes/local/htmlchecker/brickfield_accessibility_guideline.php @@ -85,7 +85,7 @@ class brickfield_accessibility_guideline { $csv = fopen(dirname(__FILE__) .'/guidelines/translations/'. $domain .'.txt', 'r'); if ($csv) { - while ($translation = fgetcsv($csv)) { + while ($translation = fgetcsv($csv, escape: '\\')) { if (count($translation) == 4) { $this->translations[$translation[0]] = [ 'title' => $translation[1], diff --git a/admin/tool/httpsreplace/cli/url_replace.php b/admin/tool/httpsreplace/cli/url_replace.php index b8e41163691..72eaecbb561 100644 --- a/admin/tool/httpsreplace/cli/url_replace.php +++ b/admin/tool/httpsreplace/cli/url_replace.php @@ -85,9 +85,9 @@ if ($options['replace']) { $results = $urlfinder->http_link_stats(); asort($results); $fp = fopen('php://stdout', 'w'); - fputcsv($fp, ['clientsite', 'httpdomain', 'urlcount']); + fputcsv($fp, ['clientsite', 'httpdomain', 'urlcount'], escape: '\\'); foreach ($results as $domain => $count) { - fputcsv($fp, [$SITE->shortname, $domain, $count]); + fputcsv($fp, [$SITE->shortname, $domain, $count], escape: '\\'); } fclose($fp); } diff --git a/analytics/classes/dataset_manager.php b/analytics/classes/dataset_manager.php index 811bf7cca6e..2c1bb9d0497 100644 --- a/analytics/classes/dataset_manager.php +++ b/analytics/classes/dataset_manager.php @@ -148,7 +148,7 @@ class dataset_manager { return false; } foreach ($data as $line) { - fputcsv($fh, $line); + fputcsv($fh, $line, escape: '\\'); } fclose($fh); @@ -290,12 +290,12 @@ class dataset_manager { $rh = $file->get_content_file_handle(); // Copy the var names as they are, all files should have the same var names. - $varnames = fgetcsv($rh); + $varnames = fgetcsv($rh, escape: '\\'); - $analysablesvalues[] = fgetcsv($rh); + $analysablesvalues[] = fgetcsv($rh, escape: '\\'); // Copy the columns as they are, all files should have the same columns. - $columns = fgetcsv($rh); + $columns = fgetcsv($rh, escape: '\\'); } // Merge analysable values skipping the ones that are the same in all analysables. @@ -316,9 +316,9 @@ class dataset_manager { throw new \moodle_exception('errorcannotwritedataset', 'analytics', '', $tmpfilepath); } - fputcsv($wh, $varnames); - fputcsv($wh, $values); - fputcsv($wh, $columns); + fputcsv($wh, $varnames, escape: '\\'); + fputcsv($wh, $values, escape: '\\'); + fputcsv($wh, $columns, escape: '\\'); // Iterate through all files and add them to the tmp one. We don't want file contents in memory. foreach ($files as $file) { @@ -402,11 +402,11 @@ class dataset_manager { $calculations = array(); - $headers = fgetcsv($rh); + $headers = fgetcsv($rh, escape: '\\'); // Get rid of the sampleid column name. array_shift($headers); - while ($columns = fgetcsv($rh)) { + while ($columns = fgetcsv($rh, escape: '\\')) { $uniquesampleid = array_shift($columns); // Unfortunately fgetcsv does not respect line's var types. diff --git a/competency/tests/generator/behat_core_competency_generator.php b/competency/tests/generator/behat_core_competency_generator.php index 687a35abad7..ddecf9c661e 100644 --- a/competency/tests/generator/behat_core_competency_generator.php +++ b/competency/tests/generator/behat_core_competency_generator.php @@ -209,7 +209,7 @@ class behat_core_competency_generator extends behat_generator_base { */ protected function preprocess_plan(array $data): array { if (isset($data['competencies'])) { - $competencies = array_map('trim', str_getcsv($data['competencies'])); + $competencies = array_map('trim', str_getcsv($data['competencies'], escape: '\\')); $data['competencyids'] = array_map([$this, 'get_competency_id'], $competencies); unset($data['competencies']); diff --git a/grade/edit/outcome/import.php b/grade/edit/outcome/import.php index e3a5cc82d32..5fc78d4f9ed 100644 --- a/grade/edit/outcome/import.php +++ b/grade/edit/outcome/import.php @@ -112,7 +112,7 @@ if ($handle = fopen($imported_file, 'r')) { // data should be separated by a ';'. *NOT* by a comma! TODO: version 2.0 // or whenever we can depend on PHP5, set the second parameter (8192) to 0 (unlimited line length) : the database can store over 128k per line. - while ( $csv_data = fgetcsv($handle, 8192, ';', '"')) { // if the line is over 8k, it won't work... + while ( $csv_data = fgetcsv($handle, 8192, ';', '"', '\\')) { // if the line is over 8k, it won't work... $line++; // be tolerant on input, as fgetcsv returns "an array comprising a single null field" on blank lines diff --git a/lib/csvlib.class.php b/lib/csvlib.class.php index 67d72f91297..88a76c9f69e 100644 --- a/lib/csvlib.class.php +++ b/lib/csvlib.class.php @@ -126,7 +126,7 @@ class csv_import_reader { $columns = array(); // str_getcsv doesn't iterate through the csv data properly. It has // problems with line returns. - while ($fgetdata = fgetcsv($fp, 0, $csv_delimiter, $enclosure)) { + while ($fgetdata = fgetcsv($fp, 0, $csv_delimiter, $enclosure, '\\')) { // Check to see if we have an empty line. if (count($fgetdata) == 1) { if ($fgetdata[0] !== null) { @@ -204,7 +204,7 @@ class csv_import_reader { return false; } $fp = fopen($filename, "r"); - $line = fgetcsv($fp); + $line = fgetcsv($fp, escape: '\\'); fclose($fp); if ($line === false) { return false; @@ -234,7 +234,7 @@ class csv_import_reader { return false; } //skip header - return (fgetcsv($this->_fp) !== false); + return (fgetcsv($this->_fp, escape: '\\') !== false); } /** @@ -246,7 +246,7 @@ class csv_import_reader { if (empty($this->_fp) or feof($this->_fp)) { return false; } - if ($ser = fgetcsv($this->_fp)) { + if ($ser = fgetcsv($this->_fp, escape: '\\')) { return $ser; } else { return false; @@ -449,7 +449,7 @@ class csv_export_writer { } } $delimiter = csv_import_reader::get_delimiter($this->delimiter); - fputcsv($this->fp, $row, $delimiter, $this->csvenclosure); + fputcsv($this->fp, $row, $delimiter, $this->csvenclosure, '\\'); } /** diff --git a/lib/mlbackend/php/classes/processor.php b/lib/mlbackend/php/classes/processor.php index d5b3fbf8a19..db972c83a32 100644 --- a/lib/mlbackend/php/classes/processor.php +++ b/lib/mlbackend/php/classes/processor.php @@ -126,7 +126,7 @@ class processor implements \core_analytics\classifier, \core_analytics\regressor $samples = array(); $targets = array(); - while (($data = fgetcsv($fh)) !== false) { + while (($data = fgetcsv($fh, escape: '\\')) !== false) { $sampledata = array_map('floatval', $data); $samples[] = array_slice($sampledata, 0, $metadata['nfeatures']); $targets[] = intval($data[$metadata['nfeatures']]); @@ -189,7 +189,7 @@ class processor implements \core_analytics\classifier, \core_analytics\regressor $sampleids = array(); $samples = array(); $predictions = array(); - while (($data = fgetcsv($fh)) !== false) { + while (($data = fgetcsv($fh, escape: '\\')) !== false) { $sampledata = array_map('floatval', $data); $sampleids[] = $data[0]; $samples[] = array_slice($sampledata, 1, $metadata['nfeatures']); @@ -270,7 +270,7 @@ class processor implements \core_analytics\classifier, \core_analytics\regressor $samples = array(); $targets = array(); - while (($data = fgetcsv($fh)) !== false) { + while (($data = fgetcsv($fh, escape: '\\')) !== false) { $sampledata = array_map('floatval', $data); $samples[] = array_slice($sampledata, 0, $metadata['nfeatures']); @@ -535,8 +535,8 @@ class processor implements \core_analytics\classifier, \core_analytics\regressor * @return array */ protected function extract_metadata($fh) { - $metadata = fgetcsv($fh); - return array_combine($metadata, fgetcsv($fh)); + $metadata = fgetcsv($fh, escape: '\\'); + return array_combine($metadata, fgetcsv($fh, escape: '\\')); } /** diff --git a/lib/phpunit/classes/phpunit_dataset.php b/lib/phpunit/classes/phpunit_dataset.php index fbb8a3cd9f4..7339c87f8a4 100644 --- a/lib/phpunit/classes/phpunit_dataset.php +++ b/lib/phpunit/classes/phpunit_dataset.php @@ -282,7 +282,7 @@ class phpunit_dataset { rewind($fh); // We just accept default, delimiter = comma, enclosure = double quote. - while ( ($row = fgetcsv($fh) ) !== false ) { + while ( ($row = fgetcsv($fh, escape: '\\') ) !== false ) { if (empty($this->columns[$tablename])) { $this->columns[$tablename] = $row; } else { diff --git a/mod/bigbluebuttonbn/classes/output/recording_row_playback.php b/mod/bigbluebuttonbn/classes/output/recording_row_playback.php index 448554a436a..32ee40b9883 100644 --- a/mod/bigbluebuttonbn/classes/output/recording_row_playback.php +++ b/mod/bigbluebuttonbn/classes/output/recording_row_playback.php @@ -115,7 +115,7 @@ class recording_row_playback implements renderable, templatable { $issafeformat = false; // Now check the list of safe formats. if ($safeformats = config::get('recording_safe_formats')) { - $safeformatarray = str_getcsv($safeformats); + $safeformatarray = str_getcsv($safeformats, escape: '\\'); $issafeformat = in_array($playback['type'], $safeformatarray); } return ($canmanagerecordings && $canviewallformats) || $issafeformat;