Skip to content

Search block double-encodes apostrophes in the input value on search results page #76010

@katag9k

Description

@katag9k

Description

When searching for a term containing an apostrophe (e.g. "ada's"), the search input field on the results page displays ada's instead of ada's. This is because get_search_query() returns a pre-escaped string, and WP_HTML_Tag_Processor::set_attribute() escapes it again, causing double-encoding.

Step-by-step reproduction instructions

  1. Add a Search block to any page or template
  2. On the frontend, search for a term containing an apostrophe, e.g. ada's
  3. On the search results page, observe the search input field displays ada's instead of ada's

Screenshots, screen recording, code snippet

Image

Environment info

The bug exists in the latest trunk. The issue is in packages/block-library/src/search/index.php line 82. The fix is to pass false to get_search_query() so set_attribute() handles escaping:

// Before:
$input->set_attribute( 'value', get_search_query() );

// After:
$input->set_attribute( 'value', get_search_query( false ) );

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Labels

[Block] SearchAffects the Search Block - used to display a search field[Status] In ProgressTracking issues with work in progress[Type] BugAn existing feature does not function as intended

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions