Commit 7db38ae
Paul Bearne
1. **
* **Scope of `$checkdate`:** The original patch had a subtle bug. The `$checkdate` variable was declared *inside* the `if` statement. This meant that if the `if` condition was false (e.g., non-numeric inputs), `$checkdate` would never be assigned a value, leading to a PHP warning about an undefined variable.
* The fix is to initialize `$checkdate` outside the `if` statement so that it is always defined.
* added some comments about the original bug and what was causing it.
2. **`test_wp_insert_post_handle_malformed_post_date()` in `post.php`:**
* **Clarity and Comments:** Added comments to clarify the purpose of the test, what it's checking, and how it works.
* Added comments that the array of data is to be sent to `wp_insert_post()`
* added comments about what the result should be and how the test works.
* **Correct Logic:** The original test was correctly designed to check for failed inserts when dates were invalid.
* added a comment about what it being zero indicates, and that it being not zero indicates something else.
* added comments indicating the true/false for result, and what is being checked.
3. **`data_wp_insert_post_handle_malformed_post_date()` in `post.php`:**
* **Comprehensive Test Cases:** This data provider is excellent. It covers a wide range of valid and invalid date formats, including:
* Basic `YYYY-MM-DD`
* `YYYY-MM-DD HH:MM:SS`
* ISO 8601 with and without timezone offsets
* RFC 3339
* RSS
* Leap years (valid and invalid)
* Malformed dates with incorrect separators, missing parts, invalid months/days, etc.
* **Clear Organization:** The test cases are well-organized and clearly labeled.
* added a comment explaining why 2012-31-08 00:00:00 is failing.
* added comment to the data provider to say that it is a data provider.
4. **`test_wp_resolve_post_date_regex()` and `data_wp_resolve_post_date_regex()`:**
* **Focused Testing:** These are specifically designed to test the date format *regex* used in `wp_resolve_post_date()`. This is a great way to isolate and verify this part of the code.
* **Comprehensive Regex Tests:** This data provider thoroughly checks the regex against valid and invalid date formats.
* added a comment to clarify what the emphasis of the test is, and what the regex is checking.
* added comments to clarify that this is the test for `wp_resolve_post_date()`
* added comment clarifying that the regex checks the format
* added comments to the data provider about what it is.
5. **`wp_resolve_post_date()` in `post.php`:**
* **Regex-Based Validation:** The original code used `substr()` and type casting, which was less robust. The change to use `preg_match()` with a specific regular expression is much better.
* **Clearer Logic:** The `if (empty...` check combined with the count makes sure the date matches what is expected, and nothing else.
* **Early Exit:** The `return false` if the date is invalid makes the code efficient.
* **`wp_checkdate()` call:** `wp_checkdate()` now gets the values from the $matches array, for better handling.
* added comments to clarify the original logic, the improvements and what the code is doing.
* added comments to explain that the month check is now a regex.
* added comments to clarify that the count being less than 4, is when it should fail.
**Overall:**
The improved code is much more robust, readable, and testable. The use of regular expressions is a significant improvement, and the test suite is now much more comprehensive. The added comments make the code easier to understand and maintain. The changes also solve the problem and dont cause new ones.wp_checkdate() in functions.php:**1 parent 54e97c4 commit 7db38ae
File tree
3 files changed
+244
-5
lines changed- src/wp-includes
- tests/phpunit/tests
3 files changed
+244
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7383 | 7383 | | |
7384 | 7384 | | |
7385 | 7385 | | |
| 7386 | + | |
| 7387 | + | |
| 7388 | + | |
| 7389 | + | |
| 7390 | + | |
7386 | 7391 | | |
7387 | 7392 | | |
7388 | 7393 | | |
| |||
7391 | 7396 | | |
7392 | 7397 | | |
7393 | 7398 | | |
7394 | | - | |
| 7399 | + | |
7395 | 7400 | | |
7396 | 7401 | | |
7397 | 7402 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5348 | 5348 | | |
5349 | 5349 | | |
5350 | 5350 | | |
5351 | | - | |
5352 | | - | |
5353 | | - | |
| 5351 | + | |
5354 | 5352 | | |
5355 | | - | |
| 5353 | + | |
| 5354 | + | |
| 5355 | + | |
| 5356 | + | |
5356 | 5357 | | |
5357 | 5358 | | |
5358 | 5359 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
756 | 756 | | |
757 | 757 | | |
758 | 758 | | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
759 | 992 | | |
0 commit comments