Empty keywords sent to search results in error

Created on 11 August 2023, over 1 year ago
Updated 8 December 2023, about 1 year ago

Problem/Motivation

If you perform a search without any keywords, the HighlightSearchTerm::highlightSearch() method throws an exception due to a null being passed where it expects a string.

Steps to reproduce

Create a search page and perform a search with the "keys" query parameter set to an empty string. Check the logs and you should see an error like:

Uncaught exception 'TypeError' with message 'Drupal\google_json_api\TwigExtension\HighlightSearchTerm::highlightSearch(): Argument #2 ($term) must be of type string, null given, called in <template name> on line 42' in ../modules/contrib/google_json_api/src/TwigExtension/HighlightSearchTerm.php:47

Proposed resolution

Either handle a null parameter better, or ensure a null parameter is never being passed.

πŸ› Bug report
Status

Fixed

Version

1.4

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States SamLerner

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

Comments & Activities

Production build 0.71.5 2024