Skip to content

Fix: oEmbed format=xml is ignored when the REST route is requested with different casing - #16081

Open
hbhalodia wants to merge 4 commits into
WordPress:trunkfrom
hbhalodia:fix/issue-66723
Open

hbhalodia wants to merge 4 commits into
WordPress:trunkfrom
hbhalodia:fix/issue-66723

Conversation

@hbhalodia

Copy link
Copy Markdown

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

_oembed_rest_pre_serve_request() compared the request route to /oembed/1.0/embed as an exact string, but WP_REST_Server matches routes case-insensitively ('@^' . $route . '$@i'). A request to /wp-json/oEmbed/1.0/embed?format=xml is still dispatched to the oEmbed controller, but it fails the exact-string check, so format=xml is ignored and the response is sent as JSON.

This PR matches the route with the REST server's own pattern, the same approach r64432 took for _wp_connectors_rest_settings_dispatch() in #66330.

Changes

  • src/wp-includes/embed.php: match the route with preg_match( '@^/oembed/1.0/embed$@i', ... ) instead of !==.
  • tests/phpunit/tests/oembed/controller.php:
    • test_rest_pre_serve_request_serves_xml_for_every_route_spelling() dispatches each spelling of the route (lowercase, mixed case, uppercase, trailing newline), asserts the oEmbed controller handled it, and asserts the callback prints XML.
    • test_rest_pre_serve_request_ignores_other_routes() asserts that another route (/oEmbed/1.0/proxy) with format=xml is left for the REST server and prints nothing.

Testing instructions

  1. Publish a post and copy its URL.
  2. Request both spellings of the route:
    curl -i 'https://example.test/wp-json/oembed/1.0/embed?url=<post-url>&format=xml'
    curl -i 'https://example.test/wp-json/oEmbed/1.0/embed?url=<post-url>&format=xml'
    Without pretty permalinks, use /?rest_route=/oEmbed/1.0/embed&url=<post-url>&format=xml instead.
  3. Before this PR, the first request returns Content-Type: text/xml and the second returns JSON. With this PR, both return XML.

Automated tests:

npm run test:php -- --filter Tests_oEmbed_Controller

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Drafting the fix, the tests and this description. I reviewed the changes and ran the tests myself.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@hbhalodia
hbhalodia requested a balanced review from Copilot November 18, 2026 07:55
@github-actions

github-actions Bot commented Nov 18, 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 hbhalodia, westonruter.

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.

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.

🟢 Approval recommended

No active review issues are reported for the oEmbed route-matching change.

No open issues 🎉

What changed in this PR

Fixes oEmbed XML responses for differently cased REST routes by aligning the response handler’s route matching with the REST server.

Changes:

  • Replaces the exact route comparison with a case-insensitive regular expression.
  • Adds regression tests for lowercase, mixed-case, uppercase, and trailing-newline routes, plus a check that unrelated routes remain unaffected.
File Description
tests/​phpunit/​tests/​oembed/​controller.php Adds XML-response and unrelated-route regression tests.
src/​wp-includes/​embed.php Aligns oEmbed route matching with REST server behavior.

Review effort: Balanced

@github-actions

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.

Comment thread src/wp-includes/embed.php Resolved
Comment thread src/wp-includes/embed.php Resolved
@hbhalodia

Copy link
Copy Markdown
Author

Thanks @westonruter, For the review.

I have addressed the feedbacks.

@hbhalodia
hbhalodia requested review from westonruter and a balanced review from Copilot November 19, 2026 08:16

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.

🟢 Approval recommended

There are no active review issues for the oEmbed route-matching change.

No open issues 🎉

Review effort: Balanced

Comment thread src/wp-includes/embed.php Resolved
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.

3 participants