Repository navigation
Commit abc50fe
committed
Formatting: Document that escaping functions can take numbers.
The `esc_attr()`, `esc_html()`, `esc_js()`, `esc_textarea()`, and `esc_xml()` functions were each annotated `@param string $text`, but none of them has ever required a string at runtime. Both `wp_check_invalid_utf8()` and `_wp_specialchars()` open by casting to string, and that coercion dates to r10298 and r11380, the same year `esc_attr()` and `esc_html()` were introduced in 2.8.0. Only the annotation ever claimed otherwise, which is why passing an integer, overwhelmingly a post ID, a term ID, or a count, has always worked while still registering as a static analysis error.
Widen the annotation to `string|int|float` and cast at the top of each function. That cast is not redundant with the ones downstream: it is what makes the `$text` argument handed to the `attribute_escape`, `esc_html`, and `js_escape` filters match its documented `string` type, where callbacks previously received the raw integer or float. For `esc_textarea()` it also affects the output, since that function passed `$text` straight to `htmlspecialchars()`, so `esc_textarea( null )` emitted a deprecation notice on PHP 8.1 and later.
The `bool` type is deliberately excluded. Casting `true` yields `'1'` while `false` yields the empty string, and an empty string is indistinguishable from a missing value in any output context. The two call sites in core which pass one stay baselined rather than being permitted by the signature; one of the two is an a11y defect being addressed separately.
Regenerating the baselines drops 54 entries covering 101 errors from `tests/phpstan/baselines/argument.type.neon`, where `esc_attr()` was the largest single cluster.
Developed in WordPress#13044.
Follow-up to r11380, r63024.
See #65817.
git-svn-id: https://develop.svn.wordpress.org/trunk@63296 602fd350-edb4-49c9-b593-d223f7449a821 parent 5a96e2a commit abc50fe
2 files changed
Lines changed: 17 additions & 277 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4716 | 4716 | | |
4717 | 4717 | | |
4718 | 4718 | | |
| 4719 | + | |
4719 | 4720 | | |
4720 | | - | |
| 4721 | + | |
4721 | 4722 | | |
4722 | 4723 | | |
4723 | 4724 | | |
| 4725 | + | |
4724 | 4726 | | |
4725 | 4727 | | |
4726 | 4728 | | |
| |||
4744 | 4746 | | |
4745 | 4747 | | |
4746 | 4748 | | |
| 4749 | + | |
4747 | 4750 | | |
4748 | | - | |
| 4751 | + | |
4749 | 4752 | | |
4750 | 4753 | | |
4751 | 4754 | | |
| 4755 | + | |
4752 | 4756 | | |
4753 | 4757 | | |
4754 | 4758 | | |
| |||
4769 | 4773 | | |
4770 | 4774 | | |
4771 | 4775 | | |
| 4776 | + | |
4772 | 4777 | | |
4773 | | - | |
| 4778 | + | |
4774 | 4779 | | |
4775 | 4780 | | |
4776 | 4781 | | |
| 4782 | + | |
4777 | 4783 | | |
4778 | 4784 | | |
4779 | 4785 | | |
| |||
4794 | 4800 | | |
4795 | 4801 | | |
4796 | 4802 | | |
| 4803 | + | |
4797 | 4804 | | |
4798 | | - | |
| 4805 | + | |
4799 | 4806 | | |
4800 | 4807 | | |
4801 | 4808 | | |
| 4809 | + | |
4802 | 4810 | | |
4803 | 4811 | | |
4804 | 4812 | | |
| |||
4815 | 4823 | | |
4816 | 4824 | | |
4817 | 4825 | | |
| 4826 | + | |
4818 | 4827 | | |
4819 | | - | |
| 4828 | + | |
4820 | 4829 | | |
4821 | 4830 | | |
4822 | 4831 | | |
| 4832 | + | |
4823 | 4833 | | |
4824 | 4834 | | |
4825 | 4835 | | |
| |||
0 commit comments