Skip to content

Commit 131d3b2

Browse files
committed
Anchor date-extraction regexps with ^
Add ^ anchors to the YEAR/MONTH/DAY regex patterns so they only match date strings starting at the beginning of the input, not arbitrary substrings.
1 parent c199ff8 commit 131d3b2

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

wp-includes/sqlite/class-wp-sqlite-pdo-user-defined-functions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public function month( $field ) {
243243
* zero month parts like '2020-00-15'. PHP's strtotime() can't
244244
* parse these, so we extract the month directly from the string.
245245
*/
246-
if ( preg_match( '/\d{4}-(\d{2})/', $field, $matches ) ) {
246+
if ( preg_match( '/^\d{4}-(\d{2})/', $field, $matches ) ) {
247247
return intval( $matches[1] );
248248
}
249249
/*
@@ -267,7 +267,7 @@ public function year( $field ) {
267267
* MySQL returns 0 for YEAR('0000-00-00'). PHP's strtotime()
268268
* can't parse zero dates, so we extract the year directly.
269269
*/
270-
if ( preg_match( '/(\d{4})-\d{2}/', $field, $matches ) ) {
270+
if ( preg_match( '/^(\d{4})-\d{2}/', $field, $matches ) ) {
271271
return intval( $matches[1] );
272272
}
273273
/*
@@ -291,7 +291,7 @@ public function day( $field ) {
291291
* zero day parts like '2020-01-00'. PHP's strtotime() can't
292292
* parse these, so we extract the day directly from the string.
293293
*/
294-
if ( preg_match( '/\d{4}-\d{2}-(\d{2})/', $field, $matches ) ) {
294+
if ( preg_match( '/^\d{4}-\d{2}-(\d{2})/', $field, $matches ) ) {
295295
return intval( $matches[1] );
296296
}
297297
/*

0 commit comments

Comments
 (0)