Skip to content

Conversation

@Roy-Orbison
Copy link

A possible solution to the gotcha of relying on the behaviour of update_option(), which register_setting() does:

If the option does not exist, it will be created.

It is not obvious to developers that their option will, currently, be sanitised twice in that case. This can easily lead to data corruption, plugin crashes, etc.

This patch is a little bit of a hack inasmuch as any other underscore-prefixed private function, but I don't see another DRY way to bypass only that processing which has already been done.

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


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.

@github-actions
Copy link

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 lev0.

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

@github-actions
Copy link

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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • 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.

@Roy-Orbison Roy-Orbison force-pushed the double-filtering-sanitizing-new-options branch 3 times, most recently from 5b8b642 to a59896a Compare February 22, 2024 05:26
@Roy-Orbison
Copy link
Author

Can also confirm that new unit test fails on parent commit of this PR:

$ vendor/bin/phpunit --verbose tests/phpunit/tests/option/updateOption.php 
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHPUnit 9.6.16 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.10-2ubuntu1
Configuration: /home/roy/path/to/wordpress-develop/phpunit.xml.dist
Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

.........F                                                        10 / 10 (100%)

Time: 00:00.051, Memory: 42.50 MB

There was 1 failure:

1) Tests_Option_UpdateOption::test_stored_sanitized_value_from_update_of_nonexistent_option_should_be_same_as_that_from_add_option
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'x_y'
+'x_y_y'

/home/roy/path/to/wordpress-develop/tests/phpunit/tests/option/updateOption.php:249

@Roy-Orbison Roy-Orbison force-pushed the double-filtering-sanitizing-new-options branch from a59896a to 98bf127 Compare May 21, 2024 03:12
@Roy-Orbison Roy-Orbison force-pushed the double-filtering-sanitizing-new-options branch from 98bf127 to 004ebc6 Compare November 6, 2025 06:37
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.

1 participant