big_pipe_theme_suggestions_big_pipe_interface_preview show Notice for

Created on 24 November 2023, 6 months ago
Updated 1 December 2023, 6 months ago

Problem/Motivation

Hook big_pipe_theme_suggestions_big_pipe_interface_preview in 122 line sometimes show notice/error.

if (is_array($variables['arguments'])) {
      $arguments = preg_replace('/[^a-zA-Z0-9]/', '_', $variables['arguments']);

The code assumes that the argument is always a string, but it is not required to be so. In lazy loading, the argument can be, for example, an array, in which case it throws an error.

Steps to reproduce

example, where $arg is a array.

return [
      '#create_placeholder' => TRUE,
      '#lazy_builder' => [
        'module.lazy_load_callbacks:' . $callback,
        [
          $method,
          $arg,
        ],
      ],
    ];

Proposed resolution

check before regex if arguments has only strings??

Remaining tasks

Waiting for review

API changes

NA

Data model changes

NA

Release notes snippet

NA

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
BigPipeΒ  β†’

Last updated 13 days ago

Created by

πŸ‡΅πŸ‡±Poland Pawelgorski87

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Issue created by @Pawelgorski87
  • last update 6 months ago
    29,721 pass
  • Status changed to Needs review 6 months ago
  • Status changed to Needs work 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for reporting, we will need a test case also showing the issue too.

    Changing to current development branch.

  • last update 6 months ago
    30,674 pass, 2 fail
  • last update 6 months ago
    30,675 pass
  • Status changed to Needs review 6 months ago
  • πŸ‡»πŸ‡³Vietnam phthlaap

    Modified small line to add tests cover for the issue.

  • Status changed to Needs work 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    // Cover some case argument item is an array not string.

    Think this needs some work, read it a few times and not sure what it's testing exactly.

  • πŸ‡»πŸ‡³Vietnam phthlaap

    Created merge request and split the tests.

  • Status changed to Needs review 6 months ago
  • Status changed to RTBC 6 months ago
  • Status changed to Needs work 6 months ago
  • πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Interesting πŸ€” But: https://3v4l.org/lsbEX β€” I cannot reproduce the notice?

    What PHP version is this happening in?

  • Status changed to Needs review 6 months ago
  • πŸ‡»πŸ‡³Vietnam phthlaap

    Hi @Wim Leers, Thanks for your help to review.

    If the arguments has a array item inside it will show the notice.

    $variables['arguments'] = ['foo_bar', ['sample']];
    var_dump(preg_replace('/[^a-zA-Z0-9]/', '_', $variables['arguments']));
  • Status changed to RTBC 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave
    1) Drupal\Tests\big_pipe\Kernel\BigPipeInterfacePreviewThemeSuggestionsTest::testBigPipeThemeHookSuggestions
    Array to string conversion
    /builds/issue/drupal-3403941/core/modules/big_pipe/big_pipe.module:122
    /builds/issue/drupal-3403941/core/modules/big_pipe/tests/src/Kernel/BigPipeInterfacePreviewThemeSuggestionsTest.php:95
    /builds/issue/drupal-3403941/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
    ERRORS!
    Tests: 1, Assertions: 1, Errors: 1.
    

    Test-only results btw.

  • πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    D'oh, of course πŸ˜„ Thanks for kindly explaining that, @phthlaap! 😊

  • Status changed to Needs work 6 months ago
  • πŸ‡§πŸ‡ͺBelgium Wim Leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    This is a bug fix for ✨ Interface previews/skeleton screens through optional "preview" or "placeholder" templates Fixed .

    … and that made me realize: this should not ever be possible. Because lazy builders only allow scalar values.

    You should be getting this exception:

    A #lazy_builder callback's context may only contain scalar values or NULL.
    

    Because $variables['arguments'] comes from

      protected static function createBigPipeJsPlaceholder($original_placeholder, array $placeholder_render_array) {
        $big_pipe_placeholder_id = static::generateBigPipePlaceholderId($original_placeholder, $placeholder_render_array);
    
        $interface_preview = [];
        if (isset($placeholder_render_array['#lazy_builder'])) {
          $interface_preview = [
            '#theme' => 'big_pipe_interface_preview',
            '#callback' => $placeholder_render_array['#lazy_builder'][0],
            '#arguments' => $placeholder_render_array['#lazy_builder'][1],
          ];
    …
    

    See the test at \Drupal\Tests\Core\Render\RendererPlaceholdersTest::testNonScalarLazybuilderCallbackContext().

    So the test coverage is still missing one thing: how can some lazy builder cause big_pipe_theme_suggestions_big_pipe_interface_preview() to hit this problem, but not trigger that exception? πŸ€”

    Is big_pipe_theme_suggestions_big_pipe_interface_preview() somehow executed before

          assert(count($elements['#lazy_builder'][1]) === count(array_filter($elements['#lazy_builder'][1], function ($v) {
            return is_null($v) || is_scalar($v);
          })), "A #lazy_builder callback's context may only contain scalar values or NULL.");
    

    maybe?

    Or much simpler: perhaps you're developing this with assertions turned off? πŸ€” Can you try to see if you can reproduce the originally reported problem when assertions are enabled? πŸ™

    Then the proper solution is still not to do the proposed change, but instead convert that assert() to an if (…) { throw new \LogicException(); } .

    If my analysis is wrong, it should be possible to disprove it with a test.

Production build 0.69.0 2024