Skip to content

Search block: double-encodes apostrophes in the input value#76023

Merged
Mamaduka merged 1 commit intoWordPress:trunkfrom
Mayank-Tripathi32:fix/search-block-double-encoding-apostrophe
Mar 2, 2026
Merged

Search block: double-encodes apostrophes in the input value#76023
Mamaduka merged 1 commit intoWordPress:trunkfrom
Mayank-Tripathi32:fix/search-block-double-encoding-apostrophe

Conversation

@Mayank-Tripathi32
Copy link
Contributor

closes #76010

What?

Fixes the double-encoding of special characters (e.g., apostrophes) in the Search block's input field on the search results page.

Why?

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 happens because get_search_query() returns a pre-escaped string (via esc_attr()), and WP_HTML_Tag_Processor::set_attribute() escapes it again, causing double-encoding.

How?

Pass false to get_search_query() in index.php so it returns the raw, unescaped query string. WP_HTML_Tag_Processor::set_attribute() already handles attribute escaping internally, so the single round of escaping is sufficient and correct.

- $input->set_attribute( 'value', get_search_query() );
+ $input->set_attribute( 'value', get_search_query( false ) );

Testing 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, verify the search input field displays ada's correctly (not ada's).
  4. Also test with other special characters like "quotes", , and &ampersand to confirm they render correctly without double-encoding.

Testing Instructions for Keyboard

  1. Use Tab to navigate to the search input field.
  2. Type a search term containing an apostrophe and press Enter.
  3. On the results page, Tab back to the search input and verify the displayed value is correct.

Screencast

Search.v2.mov

…s `false` to `get_search_query()` so it returns the unescaped\nquery string. `WP_HTML_Tag_Processor::set_attribute()` already\nhandles attribute escaping, so pre-escaping from `get_search_query()`\ncaused double-encoding (e.g. `ada&WordPress#39;s` instead of `ada's`).
@github-actions
Copy link

github-actions bot commented Feb 27, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Mayank-Tripathi32 <mayanktripathi32@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: katag9k <katag9k@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions bot added the [Package] Block library /packages/block-library label Feb 27, 2026
@Mayank-Tripathi32 Mayank-Tripathi32 added [Block] Search Affects the Search Block - used to display a search field [Type] Bug An existing feature does not function as intended labels Feb 27, 2026
Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mamaduka Mamaduka added the props-bot Manually triggers Props Bot to ensure the list of props is up to date. label Mar 2, 2026
@github-actions github-actions bot removed the props-bot Manually triggers Props Bot to ensure the list of props is up to date. label Mar 2, 2026
@Mamaduka Mamaduka merged commit 2c0c301 into WordPress:trunk Mar 2, 2026
50 of 53 checks passed
@github-actions github-actions bot added this to the Gutenberg 22.7 milestone Mar 2, 2026
gziolo pushed a commit that referenced this pull request Mar 3, 2026
Co-authored-by: Mayank-Tripathi32 <mayanktripathi32@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: katag9k <katag9k@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Search Affects the Search Block - used to display a search field [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants