Problem/Motivation

Views that generate requests with a huge amount of arguments (more than 3500) give WSOD.
The issue was reproduced on commerce order view with the amount of order items more than 3500.

Steps to reproduce

It was reproduced on commerce order view with a number of order items of more than 3500, so
1. Install commerce module
2. Create an order with the number of order items more than 3500.
3. Go to the order view page.

Expected result

Page (view) opened.

Actual result

The website encountered an unexpected error. Please try again later.
Error in the watchdog: TypeError: Cannot assign null to property Drupal\views\Plugin\views\argument\ArgumentPluginBase::$operator of type string in Drupal\views\Plugin\views\argument\NumericArgument->title() (line 63 of /usr/www/users/cbefce/web/core/modules/views/src/Plugin/views/argument/NumericArgument.php).

Root cause of issue

web/core/modules/views/src/Plugin/views/HandlerBase::breakString gives unexpected results in case of using a string with a huge amount of filter parameters, like "N1+N2+N3....+N3500" (it breaks somewhere at a number of filters ~ 3500).
The reason for that is preg_match can't handle a long string: For the longer string, the issue could be related to the length of the string causing a problem in PHP's regex engine. PHP has a limit on the size of the string it can process with regular expressions, and very long strings can lead to unexpected behavior, such as failing to match.

Proposed resolution

Fix web/core/modules/views/src/Plugin/views/HandlerBase::breakString to avoid using preg_match.

Issue fork drupal-3409401

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

Igor Ukhan created an issue. See original summary.

Ihor Ukhan’s picture

StatusFileSize
new1.91 KB

Here is the path to replace preg_match in the Drupal\views\Plugin\views/HandlerBase::breakString
All the tests Drupal\Tests\views\Functional\HandlerHandlerTest::testBreakString passed

Ihor Ukhan’s picture

StatusFileSize
new1.94 KB

Here is the updated patch that passed all the tests

Ihor Ukhan’s picture

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

naveenvalecha’s picture

Status: Active » Needs review

I have used #3 and it worked like a charm for me. It also fixed the issue for filtering a string containing '':" in it.
Example - topic:sci-fi+topic:fantasy

I have converted #3 patch to a PR https://git.drupalcode.org/project/drupal/-/merge_requests/8417

naveenvalecha’s picture

Assigned: Ihor Ukhan » Unassigned
Status: Needs review » Reviewed & tested by the community

Setting it to RTBC as the work in #8 is not mine

catch’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs tests

This could use some test coverage if possible.

smustgrave’s picture

Status: Needs review » Needs work

For the test coverage

Akhil Babu made their first commit to this issue’s fork.

akhil babu’s picture

Status: Needs work » Needs review

Added tests.

lendude’s picture

Status: Needs review » Needs work

Looks good, one more test case would be nice.

Can we come up with other cases that the regex might have missed like in #8 and make sure we are ok with that?

bharath-kondeti made their first commit to this issue’s fork.

bharath-kondeti’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests +Needs Review Queue Initiative

believe feedback for additional test coverage has been addressed.

quietone’s picture

Title: Drupal\views\Plugin\views\HandlerBase::breakString works unexpectedly for a views with a huge amount of filters/parameters in a view » Views HandlerBase::breakString works unexpectedly for a views with a huge amount of filters/parameters

Trying for an easier to read title

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

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

shalini_jha’s picture

Status: Needs work » Needs review

I reviewed the merge request and found some conflicts, so I rebased and resolved them. The pipeline has also passed successfully, so I’m moving it back to "Needs Review."

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Rebase seems fine.

quietone’s picture

Status: Reviewed & tested by the community » Needs work

I left some comments in the MR. I also updated credit.

shalini_jha’s picture

Status: Needs work » Needs review

I have reviewed all the feedback and implemented the necessary changes accordingly. After applying the updates, I re-ran the pipeline, and it is working as expected. I have also verified the empty string case, and it is functioning correctly without any issues. Moving this forward for your review. Kindly review.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Feedback appears to be addressed

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Made a suggestion to change the code on the MR.

shalini_jha’s picture

Status: Needs work » Needs review

I have updated the if condition to handle the scenario, and after testing, the test is now passing successfully. I am moving this for review. Please take a look and let me know if it makes sense to you.

smustgrave’s picture

Status: Needs review » Needs work

For the scenario you saw a failure in can we add test coverage for that one too please.

If you are another contributor eager to jump in, please allow the previous poster at least 48 hours to respond to feedback first, so they have the opportunity to finish what they started!

shalini_jha’s picture

Thank you @smustgrave for the review & feedback. the scenario i have mentioned is the existing test that is failing after the code change

shalini_jha’s picture

Status: Needs work » Needs review

I am moving this for review. Please take a look and let me know if it makes sense, or if any additional tests need to be added?

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Nope think that should be good.

longwave’s picture

Status: Reviewed & tested by the community » Needs work

Some nits about comments.

shalini_jha’s picture

Status: Needs work » Needs review

I have addressed all the feedback, including updating the comment for the single-word condition to improve clarity. Please let me know if we need to assert the single word in the test for further clarification.

Moving this to NR , Kindly review.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Believe feedback has been addressed

quietone’s picture

Status: Reviewed & tested by the community » Needs work

https://git.drupalcode.org/project/drupal/-/merge_requests/8417/diffs#note_442553 @alexpott pointed out cases where the new code and the old produce different results. I don't see those test cases. If they are the, add a comment in the code.

To test that the results have not change I removed the changes from breakString and all the long string test cases from testBreakString. I expected the test to pass, it did not. These are the cases that failed.

  1. HandlerBase::breakString('word:word1+word:word2+word:word3');
  2. HandlerBase::breakString('word:word1 word:word2 word:word3');
  3. HandlerBase::breakString('word:word1,word:word2,word:word3');
  4. HandlerBase::breakString('word:word1');

How will this change of behavior affects sites?

grapefruitjuice’s picture

Until we are waiting for upgrading to D11, on the 10.4.x branch(we tested it on the 10.4.7 version) we have an error when we're trying to apply patches from this topic:

patching file modules/views/src/Plugin/views/HandlerBase.php
Hunk #1 FAILED at 742.
1 out of 1 hunk FAILED -- saving rejects to file modules/views/src/Plugin/views/HandlerBase.php.rej

So, I've updated the patch to the particular 10.4.x branch, coz we really need it and could not wait until we move to 11 version (I took the code from the pull request).

If anybody has the same problem with patching 10.4.x core, feel free to use the updated patch.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.