[wp-trac] [WordPress Trac] #54186: Cast string to int in `wp_checkdate`

WordPress Trac noreply at wordpress.org
Thu Nov 6 23:36:08 UTC 2025


#54186: Cast string to int in `wp_checkdate`
--------------------------+-------------------------
 Reporter:  swissspidy    |       Owner:  swissspidy
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:  6.1
Component:  Date/Time     |     Version:
 Severity:  normal        |  Resolution:  fixed
 Keywords:  has-patch     |     Focuses:
--------------------------+-------------------------

Comment (by johnjamesjacoby):

 In [changeset:"61172" 61172]:
 {{{
 #!CommitTicketReference repository="" revision="61172"
 Date/Time: Prevent a PHP exception when inserting posts with a partially
 malformed `post_date`.

 This commit updates `wp_resolve_post_date()` to use a regular expression
 for parsing the date string into year, month, and day matches. This
 approach handles missing leading zeros more reliably than `substr()` while
 remaining performant (see #57683).

 It also adds checks and type-casting to `wp_checkdate()` variables before
 passing them into PHP's `checkdate()` function to avoid the potential for
 a `TypeError` in PHP 8 and newer (see #54186).

 Lastly, it includes 2 new unit tests (with data providers) to cover an
 array of valid and invalid date formats (YYYY-MM-DD, YYYY-MM-DD HH:MM:SS,
 ISO 8601, RSS, leap years, malformed inputs, etc...)

 Props alordiel, desrosj, johnbillion, johnjamesjacoby, johnregan3,
 modius5150, nacin, pbearne.

 Fixes #26798.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54186#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list