hellofromTonya
dfef2c917f
Formatting: Use is_scalar() in sanitize_key().
...
This is a follow-up to [52292] which introduced `is_string()` to check the given key is a string to be sanitized, else the key is set to an empty string.
`sanitize_key()` is clearly identified (in the documentation) to only work with ''string'' keys. However, it had a bug in it that allowed non-strings to pass through it:
* A non-scalar "key" would throw a PHP Warning (which was resolved in [52292].
* A non-string scalar "key" was handled by the PHP native `strtolower()` which converted it into a string.
While `is_string()` is valid, non-string scalar types passed as the key to be sanitized were being set to an empty string. Given that `strtolower()` handles these without error or deprecation as of PHP 8.1, `is_scalar()` protects the website from issues while retaining the past behavior of converting integer keys (for example) into a string.
Changes include:
* Using `is_scalar()` instead of `is_string()`
* Refactor for readability and less code
* More tests
Please note, this does not change the behavior of the function, nor redefine it to now accept non-string scalars.
References:
* https://developer.wordpress.org/reference/functions/sanitize_key/
* https://www.php.net/manual/en/function.strtolower.php
Follow-up [52292].
Props wppunk, hellofromTonya, costdev, jrf.
Fixes #54160 .
Built from https://develop.svn.wordpress.org/trunk@52370
git-svn-id: http://core.svn.wordpress.org/trunk@51962 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-12-14 15:01:03 +00:00
..
2021-12-14 01:57:26 +00:00
2021-11-09 02:17:17 +00:00
2021-12-06 06:20:27 +00:00
2021-12-14 01:57:26 +00:00
2021-10-03 17:51:06 +00:00
2021-12-14 01:57:26 +00:00
2021-12-11 19:50:59 +00:00
2021-11-26 03:06:03 +00:00
2021-11-16 00:04:01 +00:00
2021-05-24 02:18:58 +00:00
2021-12-14 08:30:04 +00:00
2021-08-10 13:45:57 +00:00
2021-11-26 00:43:01 +00:00
2021-12-07 12:20:02 +00:00
2021-12-06 21:30:03 +00:00
2021-12-13 15:20:03 +00:00
2021-11-18 13:50:05 +00:00
2021-08-10 13:04:57 +00:00
2021-11-18 13:50:05 +00:00
2021-11-07 23:04:56 +00:00
2021-12-07 00:02:02 +00:00
2021-06-21 06:06:57 +00:00
2021-12-14 01:57:26 +00:00
2021-08-11 09:08:01 +00:00
2021-07-02 14:35:58 +00:00
2021-12-14 01:57:26 +00:00
2021-12-03 19:39:00 +00:00
2021-12-11 11:16:03 +00:00
2021-11-08 23:06:58 +00:00
2021-05-20 00:04:56 +00:00
2021-06-08 23:32:56 +00:00
2021-11-15 01:09:59 +00:00
2021-11-18 13:50:05 +00:00
2021-11-07 01:36:57 +00:00
2021-05-25 18:47:59 +00:00
2021-12-06 21:30:03 +00:00
2021-09-09 12:39:59 +00:00
2021-11-16 14:57:02 +00:00
2021-09-09 13:03:55 +00:00
2021-09-09 13:03:55 +00:00
2021-09-09 12:39:59 +00:00
2021-09-09 13:03:55 +00:00
2021-11-15 03:43:59 +00:00
2021-10-30 20:26:59 +00:00
2021-05-24 07:38:58 +00:00
2021-08-03 11:12:55 +00:00
2021-11-19 19:05:59 +00:00
2021-11-23 21:37:01 +00:00
2021-11-28 13:53:00 +00:00
2021-11-23 21:37:01 +00:00
2021-12-12 14:54:00 +00:00
2021-06-15 15:22:58 +00:00
2021-07-28 10:06:59 +00:00
2021-12-01 12:17:00 +00:00
2021-12-07 12:20:02 +00:00
2021-10-22 16:09:59 +00:00
2021-12-10 20:30:05 +00:00
2021-10-04 20:44:02 +00:00
2021-12-11 19:50:59 +00:00
2021-12-11 19:50:59 +00:00
2021-10-18 17:52:58 +00:00
2021-12-10 20:30:05 +00:00
2021-12-07 12:20:02 +00:00
2021-09-08 23:29:58 +00:00
2021-11-30 17:18:01 +00:00
2021-06-05 15:46:57 +00:00
2021-12-01 13:22:01 +00:00
2021-09-22 21:23:00 +00:00
2021-11-07 01:36:57 +00:00
2021-11-12 23:51:59 +00:00
2021-10-01 15:00:58 +00:00
2021-12-01 12:17:00 +00:00
2021-12-06 21:30:03 +00:00
2021-12-06 21:30:03 +00:00
2021-11-07 01:36:57 +00:00
2021-12-06 21:30:03 +00:00
2021-09-09 20:39:58 +00:00
2021-09-09 20:39:58 +00:00
2021-12-07 12:20:02 +00:00
2021-11-09 01:10:59 +00:00
2021-12-07 12:20:02 +00:00
2021-07-30 19:35:58 +00:00
2021-06-15 10:24:57 +00:00
2021-10-15 05:04:56 +00:00
2021-11-19 14:44:01 +00:00
2021-12-07 12:20:02 +00:00
2021-07-30 19:35:58 +00:00
2021-07-30 19:35:58 +00:00
2021-05-15 17:38:05 +00:00
2021-11-20 00:07:59 +00:00
2021-12-07 12:20:02 +00:00
2021-11-01 14:31:00 +00:00
2021-12-07 12:20:02 +00:00
2021-12-05 18:02:08 +00:00
2021-12-02 20:45:01 +00:00
2021-12-14 01:57:26 +00:00
2021-12-14 02:46:00 +00:00
2021-12-07 12:20:02 +00:00
2021-09-22 21:23:00 +00:00
2021-11-19 14:44:01 +00:00
2021-06-23 01:34:58 +00:00
2021-11-16 01:43:00 +00:00
2021-11-07 01:36:57 +00:00
2021-08-16 20:17:57 +00:00
2021-12-07 17:49:01 +00:00
2021-07-30 19:35:58 +00:00
2021-07-30 19:35:58 +00:00
2021-11-19 20:24:00 +00:00
2021-12-07 12:20:02 +00:00
2021-11-08 14:22:57 +00:00
2021-11-23 21:37:01 +00:00
2021-11-10 00:41:00 +00:00
2021-12-14 09:49:00 +00:00
2021-05-25 08:27:57 +00:00
2021-08-10 19:44:59 +00:00
2021-12-07 12:20:02 +00:00
2021-11-29 09:52:00 +00:00
2021-05-15 17:38:05 +00:00
2021-12-14 15:01:03 +00:00
2021-12-10 20:30:05 +00:00
2021-09-02 08:30:58 +00:00
2021-11-19 15:14:00 +00:00
2021-11-11 16:29:00 +00:00
2021-11-30 00:24:27 +00:00
2021-12-06 21:30:03 +00:00
2021-12-07 12:20:02 +00:00
2021-12-06 11:08:01 +00:00
2021-12-07 12:20:02 +00:00
2021-12-12 14:54:00 +00:00
2021-12-10 20:30:05 +00:00
2021-11-17 15:56:03 +00:00
2021-12-07 12:20:02 +00:00
2021-11-11 18:32:00 +00:00
2021-08-17 22:08:57 +00:00
2021-11-18 15:11:59 +00:00
2021-07-06 20:21:57 +00:00
2021-12-01 12:17:00 +00:00
2021-11-18 13:57:01 +00:00
2021-12-07 12:20:02 +00:00
2021-11-08 10:48:59 +00:00
2021-11-18 16:04:00 +00:00
2021-12-01 13:22:01 +00:00
2021-11-18 13:50:05 +00:00
2021-11-18 13:50:05 +00:00
2021-12-14 09:09:01 +00:00
2021-06-15 15:22:58 +00:00
2021-12-06 21:30:03 +00:00
2021-11-10 01:26:59 +00:00
2021-12-14 01:57:26 +00:00
2021-06-15 15:22:58 +00:00
2021-05-15 17:38:05 +00:00
2021-12-12 14:54:00 +00:00
2021-12-10 20:30:05 +00:00
2021-05-25 14:20:57 +00:00
2021-11-08 19:19:58 +00:00
2021-12-09 09:56:04 +00:00
2021-11-30 00:24:27 +00:00
2021-12-14 09:49:00 +00:00
2021-12-10 00:06:04 +00:00
2021-12-10 20:30:05 +00:00
2021-12-14 15:01:03 +00:00
2021-12-13 10:21:07 +00:00
2021-11-30 21:03:00 +00:00