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
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | csv_serialization-php-deprecation-function-3389415-8-on-8x-1x.patch | 2.5 KB | ericgsmith |
| #8 | csv_serialization-php-deprecation-function-3389415-8.patch | 5.01 KB | ericgsmith |
Issue fork csv_serialization-3389415
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
Comment #2
ericgsmith commentedComment #3
ericgsmith commentedComment #5
ericgsmith commentedComment #6
ericgsmith commentedUpdated approached based on how the following modules add additional formats:
- hal module
- jsonapi module
Comment #7
ericgsmith commentedSorry for the noise, accidentally named the interdiff as a patch.
Comment #8
ericgsmith commentedAlright, 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.
Comment #9
david.muffley commentedConfirming 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.
Comment #10
markdorisonComment #11
markdorisonPatch no longer applies cleanly. Please re-roll in a merge request so we can utilize GitLab CI testing.
Comment #13
ericgsmith commentedComment #14
david.muffley commentedBeen 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.
Comment #16
markdorison