Repository navigation
Conversation
…get. wp_parse_widget_id() anchored its pattern with $, which also matches before a final newline, so "text-1\n" was parsed as text-1. Creating a widget through the REST API with that ID saved settings to text-1 and added "text-1\n" to the sidebar before failing with a 500 error. WP_REST_Widgets_Controller::update_item() also let an ID that matches no registered widget through when the widget is in no sidebar, so a request with only a sidebar parameter added that ID to the sidebar before failing. Fixing only the parser would send "text-1\n" down that path. The pattern now uses \z, and update_item() returns a 404 error when the widget is in no sidebar and its ID is not registered. Fixes #66434.
|
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: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
wp_parse_widget_id()anchored its pattern with$, which also matches before a final newline, so"text-1\n"was parsed as the Text widgettext-1. Creating a widget throughPOST /wp/v2/widgetswith that ID saved the new settings totext-1and added"text-1\n"to the sidebar, and then returned a 500 error.WP_REST_Widgets_Controller::update_item()also let an ID that matches no registered widget through when the widget is in no sidebar, soPUT /wp/v2/widgets/{id}with only asidebarparameter added that ID to the sidebar before returning a 500 error. Fixing only the parser would send"text-1\n"down this path, so both are fixed here.Trac ticket: https://core.trac.wordpress.org/ticket/66434
What changes
wp_parse_widget_id()anchors its pattern with\z, so an ID that ends in a newline is no longer split into a base and a number.update_item()returns the existing 404rest_widget_not_founderror when the widget is in no sidebar and its ID is not in$wp_registered_widgets. Registered widgets that are notWP_Widgetobjects can still be updated without a sidebar, astest_create_item_legacy_widgetcovers.Testing
test_does_not_parse_number_before_trailing_newline,test_create_item_rejects_id_with_trailing_newline,test_update_item_unknown_id_returns_404andtest_update_item_rejects_id_with_trailing_newline.update_item()change, the parser and create tests fail.Tests_Widgetspass (507 tests) on single site and multisite, and thecustomizegroup passes (243 tests). PHPCS reports nothing on the changed files.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code and Codex
Used for: Investigation, code, tests, local testing and PR wording. I reviewed the reasoning, the code and the test results, and I take responsibility for the contribution.
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.