PHP Type error in form redirect when deleting saved searches

Created on 24 August 2022, about 2 years ago
Updated 17 June 2023, over 1 year ago

Problem/Motivation

When deleting a saved search then _search_api_saved_searches_admin_redirect_url() relies on the ordering of elements in the page array. That is bad, we should explicitly pass the path and the rest of the array with query parameters.

Symptom:
Location https://example.com/search-api/saved-search/737413/delete
Referer https://example.com/search-api/saved-search/737413/delete
Message TypeError: Argument 2 passed to drupal_goto() must be of the type array, string given, called in includes/form.inc on line 1311 in drupal_goto() (line 682 of includes/common.inc).

That happens when I want to delete a migrated saved search where the $search->options['page'] array is ordered differently (query first, then path).

The code should not rely on the array order, we can fix that.

Proposed resolution

Pass path and rest of page array explicitly.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡¦πŸ‡ΉAustria klausi πŸ‡¦πŸ‡Ή Vienna

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

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

  • πŸ‡ΊπŸ‡¦Ukraine tibezh

    Looks good to me.
    Thanx @klausi!

  • Status changed to Needs review over 1 year ago
  • πŸ‡¦πŸ‡ΉAustria drunken monkey Vienna, Austria

    Thanks for reporting this problem, and sorry it took me so long to get back to you!
    Your analysis of the problem isn’t entirely correct, though. The problem is that it seems the function was written for use with confirm_form(), for which it produces exactly the right output. However, we then also used it for drupal_goto() and $form_state['redirect'], without realizing that they use a slightly different format. It seems nobody noticed since this will only affect anonymous users’ alerts.

    Anyways, I think the attached would be the proper fix: properly document what is being returned, and handle this accordingly in the caller. (Otherwise we’d need a second function, or a flag for which format to return.)
    Please test/review, and thanks again!

  • Status changed to RTBC over 1 year ago
  • πŸ‡¦πŸ‡ΉAustria klausi πŸ‡¦πŸ‡Ή Vienna

    Yup, this should also work. Thanks!

  • Status changed to Fixed over 1 year ago
  • πŸ‡¦πŸ‡ΉAustria drunken monkey Vienna, Austria

    Good to hear. Merged.
    Thanks again!

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

Production build 0.71.5 2024