Problem/Motivation

When using this module with a rest export view it is possible to trigger a deprecated function warning.

Deprecated function: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\Core\EventSubscriber\ActiveLinkResponseFilter->onResponse() (line 82 of /app/web/core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php)

Steps to reproduce

- With PHP 8.1 and either Drupal 9/ CSV Serialization 8.x-2.1 or Drupal 10 / CSV Serialization 3.0.0
- Create a new rest export view with any authentication restriction
- Enable CSV serialization module / as an acceptable format on the view
- Access the view as a user without authorization

The error is being triggered because:

Symfonys RouteSubscriberListener has a priority of 32, so it runs before this modules CsvSubscriber listener
The route subscriber handles the route before the CSV format is added to the request as the CSVSubscriber has not run at this point
As the authentication on the view fails an exception is thrown
The serialization modules DefaultExceptionSubscriber handles the exception via its on4xx method and tries to set the Content-Type header via this code:

// Add the MIME type from the request to send back in the header.
$headers['Content-Type'] = $request->getMimeType($format);

At that point the format is csv and null is returned.

Proposed resolution

I was able to work around this issue by adding a priority of 33 to the CsvSubscriber.

I have not found any documentation to suggest this is what custom formats should be doing - and I assume the same issue would be applicable to other modules - but I am adding this here as its where I found the issue.

Update: Having reviewed other serialization providers it appears the more common was is calling registerFormat on the NegotiationMiddleware

Remaining tasks

Review approach

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

ericgsmith created an issue. See original summary.

ericgsmith’s picture

Issue summary: View changes
ericgsmith’s picture

The last submitted patch, 3: csv_serialization-php-deprecation-function-3389415-3-test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

ericgsmith’s picture

Issue summary: View changes
ericgsmith’s picture

Updated approached based on how the following modules add additional formats:

- hal module
- jsonapi module

ericgsmith’s picture

StatusFileSize
new2.21 KB

Sorry for the noise, accidentally named the interdiff as a patch.

ericgsmith’s picture

Alright, cleaned up the coding standards and rolled a version against 8.x-1.x for anybody still on Drupal 9.

Updated the issue status. Apologies for the noise / multiple updates on this issue - think this is all ready for review now.

david.muffley’s picture

Confirming the #8 - 3.0.x patch resolves the deprecated warning during a 403, and on success serves up CSVs with the correct Content-Type header. The new implementation to register the csv format looks odd at first glance but it's how core does this too (see FileServiceProvider and JsonapiServiceProvider).

I didn't review the other patch.

markdorison’s picture

Version: 3.x-dev » 4.x-dev
markdorison’s picture

Status: Needs review » Needs work

Patch no longer applies cleanly. Please re-roll in a merge request so we can utilize GitLab CI testing.

ericgsmith’s picture

Status: Needs work » Needs review
david.muffley’s picture

Status: Needs review » Reviewed & tested by the community

Been running the patch on the 4.0 release on my prod site for 5 months without issue. All this in addition to my testing in #9 last year.

I've updated the MR to fix the merge conflicts with 4.x. Test only fails as expected, with the code changes the test passes. Calling this reviewed.

markdorison’s picture

Status: Reviewed & tested by the community » Fixed
//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support to this project makes other volunteer contributions more sustainable.
There are multiple ways to show appreciation for the work contributed to this project including:
  • Triaging issues and adding more context to existing issues.
  • Writing documentation or patches for this project.
  • Writing blog posts or speaking about it at conferences.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.