Skip to content

Term query: match non-ASCII slugs in search. Ticket #43626 - #16451

Open
MoS2mir wants to merge 2 commits into
WordPress:trunkfrom
MoS2mir:fix/43626-term-search-non-ascii-slug
Open

MoS2mir wants to merge 2 commits into
WordPress:trunkfrom
MoS2mir:fix/43626-term-search-non-ascii-slug

Conversation

@MoS2mir

@MoS2mir MoS2mir commented Dec 3, 2026

Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/43626

What is wrong

Slugs that contain non-ASCII characters (for example Arabic) are stored percent-encoded in wp_terms.slug. WP_Term_Query::get_search_sql() matched the raw search string against t.slug, so searching for the slug of an Arabic term returned nothing, while the same search for an English slug works.

What this changes

When the search string contains non-ASCII characters, get_search_sql() also matches the encoded form of the search string (utf8_uri_encode(), lowercased) against t.slug. For ASCII-only searches the generated SQL is unchanged.

A PHPUnit test is added to Tests_Term_getTerms: test_get_terms_search_matches_non_ascii_slug.

How it was verified

Checked in WordPress Playground (PHP 8.3, SQLite) with a tag named تاج1 and slug سلج1:

  • WordPress 7.1.5 and the current nightly (7.3-alpha): searching سلج1 returned no terms.
  • With this change on 7.1.5: searching سلج1 returns the tag. Searches for slug1, تاج1 and café return the same results as before.

The PHPUnit test is included but I could not run it locally (no MySQL), so CI here is its first real run.

Related

Open PRs #14187 (ticket 66279) and #14138 (ticket 66281) also change get_search_sql(), so this may need a rebase if either lands first.

Non-ASCII slugs are stored percent-encoded, so also match the encoded form of the search string against the term slug.

See #43626.
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props mohsamirdev, ravipatel.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@rvpatel

rvpatel commented Dec 3, 2026

Copy link
Copy Markdown

Test Report

Environment: wordpress-develop Docker, PHP 8.3.35, trunk 9fe0c05 + this PR (merges cleanly). Categories whose slug differs from the name, so only the slug can match. Tested with get_terms( array( 'search' => … ) ) and GET /wp/v2/categories?search=….

search Before (trunk) After (this PR)
تجربة / عربي (slug تجربة-عربي) ❌ none; REST [] ✅ found; REST returns the term
тест (slug тест-слаг) ❌ none ✅ found
Тест / ТЕСТ ❌ none ❌ still none
café, plain-slug, 100% unchanged unchanged ✅

Uppercase non-Latin searches: sanitize_title_with_dashes() runs mb_strtolower() before utf8_uri_encode(), so slugs store the encoded lowercase letters. The PR runs strtolower() after encoding, which only lowercases the hex digits, so Тест encodes to different bytes than тест. I tried this change locally:

$slug_search = utf8_uri_encode( mb_strtolower( $search, 'UTF-8' ) );

With it, тест, Тест and ТЕСТ all match, and the Arabic and ASCII results stay the same. A test case with an uppercase Cyrillic search would cover it.

Tests: tests/phpunit/tests/term/getTerms.php passes (115 tests); --group taxonomy passes (1,151 tests, 1 unrelated PHPUnit deprecation warning in Tests_WP_Generate_Tag_Cloud).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants