Skip to content

Theme Directory: Validate the locale parameter in the themes API. - #745

Closed
obenland wants to merge 1 commit into
WordPress:trunkfrom
obenland:themes/api-locale-handling
Closed

Theme Directory: Validate the locale parameter in the themes API.#745
obenland wants to merge 1 commit into
WordPress:trunkfrom
obenland:themes/api-locale-handling

Conversation

@obenland

Copy link
Copy Markdown
Member

The themes API accepts a locale request parameter and filters it into get_locale() for the remainder of the request. The only check it currently receives is is_scalar(), so any string is passed through and used as-is.

This validates it with sanitize_locale_name() and falls back to the site default when the value isn't a well-formed locale name. That matches how the locale-detection plugin already handles its own locale parameter on these sites.

Notes

  • The check lives in the constructor alongside the existing request filtering, so it applies to every caller rather than just one route. Themes_API::__construct() is the shared funnel for the themes/info/1.x endpoints, the themes/1.x REST routes, and internal wporg_themes_query_api() calls. A route-level args schema would only cover the REST routes — the info/1.x endpoints are plain PHP and also accept a serialized POST body.
  • A malformed value falls back to the default rather than setting bad_input. Flagging it would turn requests that currently succeed into 400s for clients sending values like de_DE.UTF-8, which seemed like the wrong trade for this change.
  • Well-formed values are unaffected: de_DE, ca, bal, de_DE_formal, and zh-Hans all pass through unchanged.

Tests

Adds tests/Themes_API_Test.php, covering the constructor's request handling as a whole: scalar-only fields, locale validation, favorites requests, array-of-string fields, and fields normalisation.

Full suite passes at 36 tests / 72 assertions. Reverting the production change fails 10 of the new tests and leaves the other 15 green, so the added coverage isn't coupled to the change.

🤖 Generated with Claude Code

The themes API accepts a `locale` request parameter and filters it into
`get_locale()` for the remainder of the request, but the only check it
receives is `is_scalar()`, so any string is used as-is.

Validate it with `sanitize_locale_name()` and fall back to the site
default when it isn't a well-formed locale name, matching how the
`locale-detection` plugin already handles its `locale` parameter.

The check lives in the constructor alongside the other request filtering
so it covers every caller: the `themes/info/1.x` endpoints, the
`themes/1.x` REST routes, and internal `wporg_themes_query_api()` calls.

Adds tests for the constructor's request handling.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 28, 2026 20:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

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. You can also manually ask me to refresh this list by adding the props-bot label.

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

Props obenland.

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

@bazza bazza closed this in 8b4b1e8 Jul 28, 2026
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