Problem/Motivation

When uploading a CSV file to a Chart paragraph via the "Import Data from CSV" feature, an AJAX parsererror (HTTP 200) occurs and the data is not imported. The root cause is a PHP deprecation notice emitted by fgetcsv() in ChartDataCollectorTable.php, which is rendered into the response body before the JSON payload, causing the AJAX handler to fail to parse the response.

On a second upload attempt (with an empty data table), the corrupted form state can cause an unrelated component to be inserted erroneously.

The deprecation notice reads:
Deprecated: fgetcsv(): the $escape parameter must be provided as its default value will change in .../charts/src/Element/ChartDataCollectorTable.php on line 476

This affects environments where PHP deprecation notices are rendered (e.g. development environments or servers with display_errors on), and will become a hard error in a future PHP version.

Steps to reproduce

1. Create a node with a Chart paragraph
2. In the Chart field, open the "Import Data from CSV" section
3. Upload a valid CSV file and click "Upload CSV"
4. Observe the browser console — an AJAX HTTP error with StatusText: parsererror is logged
5. The chart data table fields remain empty

Expected behaviour:
The CSV data is parsed and populated into the chart data table fields without error.

Actual behaviour:
The AJAX response fails with a parsererror due to the PHP deprecation notice being prepended to the JSON response body. On a second upload attempt the form state is corrupt and an unrelated component may be inserted.

Proposed resolution

In src/Element/ChartDataCollectorTable.php line 476, explicitly provide the $enclosure and $escape arguments to fgetcsv():

  -      while ($row = fgetcsv($handle, 0, $separator)) {
  +      while ($row = fgetcsv($handle, 0, $separator, '"', '\\')) {

This matches the historical defaults and silences the deprecation notice in PHP 8.1+, restoring correct AJAX behaviour.

CommentFileSizeAuthor
fgetcsv-escape-param.patch745 bytesjames hawthorn-byng

Issue fork charts-3595482

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

james hawthorn-byng created an issue. See original summary.

nikathone’s picture

Status: Needs review » Needs work

This is a good suggestion @james-hawthorn-byng. Could you please provide it as a MR? If in the future people need to be able to provide different values for the enclosure and $escape arguments to fgetcsv() we can make it configurable.

pfaocle’s picture

Just to note this addresses the issue for me. Thanks!

andileco made their first commit to this issue’s fork.

andileco’s picture

Status: Needs work » Needs review

I'm on a Charts issue spree, so went ahead and created the MR based on @james hawthorn-byn's post.

nikathone’s picture

Status: Needs review » Reviewed & tested by the community

  • andileco committed dd06d7d8 on 5.2.x
    fix: #3595482 fgetcsv(): $escape parameter deprecation notice breaks CSV...
andileco’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.