Verified Commit 7355949b authored by godotislate's avatar godotislate
Browse files

fix: #3605431 Missing is_string check for the sort_by Views exposed form query parameter

By: taran2l
By: lendude
parent 31b45641
Loading
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -222,7 +222,7 @@ public function exposedFormAlter(&$form, FormStateInterface $form_state) {
        'DESC' => $this->options['sort_desc_label'],
      ];
      $user_input = $form_state->getUserInput();
      if (isset($user_input['sort_by']) && isset($exposed_sorts[$user_input['sort_by']]) && isset($this->view->sort[$exposed_sorts[$user_input['sort_by']]])) {
      if (isset($user_input['sort_by']) && is_string($user_input['sort_by']) && isset($exposed_sorts[$user_input['sort_by']]) && isset($this->view->sort[$exposed_sorts[$user_input['sort_by']]])) {
        $default_sort_order = $this->view->sort[$exposed_sorts[$user_input['sort_by']]]->options['order'];
      }
      else {
@@ -230,7 +230,7 @@ public function exposedFormAlter(&$form, FormStateInterface $form_state) {
        $default_sort_order = $first_sort->options['order'];
      }

      if (!isset($user_input['sort_by'])) {
      if (!isset($user_input['sort_by']) || !is_string($user_input['sort_by'])) {
        $keys = array_keys($exposed_sorts);
        $user_input['sort_by'] = array_shift($keys);
        $form_state->setUserInput($user_input);
+12 −0
Original line number Diff line number Diff line
@@ -419,6 +419,18 @@ public function testExposedSortAndItemsPerPage(): void {
    $this->assertCacheContexts($contexts);
    $this->assertIds(range(1, 10, 1));

    // Test that malformed sort_by is not causing PHP errors.
    $this->drupalGet('test_exposed_form_sort_items_per_page', [
      'query' => [
        // Sort by must be a string, not an array.
        'sort_by' => [
          'aaa' => 'bbb',
        ],
      ],
    ]);
    $this->assertCacheContexts($contexts);
    $this->assertIds(range(1, 10, 1));

    $this->drupalGet('test_exposed_form_sort_items_per_page', ['query' => ['sort_order' => 'DESC']]);
    $this->assertCacheContexts($contexts);
    $this->assertIds(range(50, 41, 1));