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
| Comment | File | Size | Author |
|---|
Issue fork google_tag-3542554
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
Comment #2
saurabhkanva commentedThis patch should resolve the warning
Comment #5
ankondrat4 commentedHello,
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.
Comment #6
ankondrat4 commentedComment #7
jannakha commentedComment #8
stijndPatch #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.
Comment #10
japerrySame 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: