Problem/Motivation

Warning: Array to string

search query:
keys=elvis%20presley%20-You%27ll%20Never%20Walk%20Alone

produces a warning:

Warning: Array to string conversion in Drupal\google_tag\EventSubscriber\SearchApiSubscriber->onSearch() (line 67 of /app/web/modules/contrib/google_tag/src/EventSubscriber/SearchApiSubscriber.php)

Steps to reproduce

here's a query string:
elvis%20presley%20-You%27ll%20Never%20Walk%20Alone

these query strings are produced by bots/hackers, but they should not product any warnings/errors in the code

Proposed resolution

harden keys processing mechanism

Remaining tasks

harden keys processing mechanism

User interface changes

none

API changes

none

Data model changes

none

CommentFileSizeAuthor
#2 google_tag-354255422.patch1.78 KBsaurabhkanva

Issue fork google_tag-3542554

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

jannakha created an issue. See original summary.

saurabhkanva’s picture

StatusFileSize
new1.78 KB

This patch should resolve the warning

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

ankondrat4’s picture

Hello,
Patch #2 doesn't resolve issue when use the next search strings from bots:
-中华人民共和国成都海关能源费用托管项目合同
java -jar指定进程名称
curl -lo是什么意思
Also it blocks search functionality with php error: Error: Cannot use positional argument after named argument during unpacking in Drupal\google_tag\EventSubscriber\SearchApiSubscriber->onSearch() (line 57 of /var/www/html/web/modules/contrib/google_tag/src/EventSubscriber/SearchApiSubscriber.php).
I've created a fork and MR!130 with fix. It works for me.
Please review.

ankondrat4’s picture

Status: Active » Needs review
jannakha’s picture

stijnd’s picture

Status: Needs review » Reviewed & tested by the community

Patch #2 does not fix the issue. Applying it results in the following error, as reported by @ankondrat4:

Error: Cannot use positional argument after named argument during unpacking in Drupal\google_tag\EventSubscriber\SearchApiSubscriber->onSearch()

Tested !MR130 on a production environment running Drupal 11.3.7 / PHP 8.3. The issue no longer occurs.

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

japerry’s picture

Status: Reviewed & tested by the community » Fixed

Same bug as #3516067: EventSubscriber - SearchAPISubscriber - Keys fail on multi-dimensional arrays. Search API keys can nest more than one level (the Views fulltext "contains none" operator, two fulltext filters, or "Keywords with operators" mode), and the deeper groups reach strval().

The original MR !130 stopped the warning, but RecursiveIteratorIterator drops the keys, so "#negation" => TRUE came out as "1". An ordinary "foo -bar" search sent "foo 1 bar", which 2.0.x gets right today. array_unique() also dropped repeated terms.

I rebased the MR onto 2.0.x and pushed a follow up commit:

  • Keys are flattened recursively, skipping "#" properties (#conjunction, #negation) at every depth.
  • SearchApiSearchEventTest has a data provider for string keys, a negated term, the query from the issue summary, flat arrays, a three-level group and numeric terms.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • japerry committed cf6e88f9 on 2.0.x authored by ankondrat4
    fix: #3542554 Skip Search API key properties when flattening the search...

Status: Fixed » Closed (fixed)

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