Make WordPress Core

Changeset 46863


Ignore:
Timestamp:
12/09/2019 07:00:18 PM (7 years ago)
Author:
SergeyBiryukov
Message:

Date/Time: When determining whether to decline the month name in wp_maybe_decline_date(), take word boundaries into account.

Add more unit tests.

Props Rarst, Clorith, timon33, Xendo, SergeyBiryukov.
Merges [46862] to the 5.3 branch.
Fixes #48606.

Location:
branches/5.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/5.3

  • branches/5.3/src/wp-includes/functions.php

    r46836 r46863  
    336336                $months_genitive = $wp_locale->month_genitive;
    337337
    338                 // Match a format like 'j F Y' or 'j. F'
    339                 if ( preg_match( '#^\d{1,2}\.? [^\d ]+#u', $date ) ) {
    340 
     338                /*
     339                 * Match a format like 'j F Y' or 'j. F' (day of the month, followed by month name)
     340                 * and decline the month.
     341                 */
     342                if ( preg_match( '#\b\d{1,2}\.? [^\d ]+\b#u', $date ) ) {
    341343                        foreach ( $months as $key => $month ) {
    342                                 $months[ $key ] = '# ' . $month . '( |$)#u';
     344                                $months[ $key ] = '# ' . preg_quote( $month, '#' ) . '\b#u';
    343345                        }
    344346
    345347                        foreach ( $months_genitive as $key => $month ) {
    346                                 $months_genitive[ $key ] = ' ' . $month . '$1';
     348                                $months_genitive[ $key ] = ' ' . $month;
    347349                        }
    348350
     
    350352                }
    351353
    352                 // Match a format like 'F jS' or 'F j' and change it to 'j F'
    353                 if ( preg_match( '#^[^\d ]+ \d{1,2}(st|nd|rd|th)? #u', trim( $date ) ) ) {
     354                /*
     355                 * Match a format like 'F jS' or 'F j' (month name, followed by day with an optional ordinal suffix)
     356                 * and change it to declined 'j F'.
     357                 */
     358                if ( preg_match( '#\b[^\d ]+ \d{1,2}(st|nd|rd|th)?\b#u', trim( $date ) ) ) {
    354359                        foreach ( $months as $key => $month ) {
    355                                 $months[ $key ] = '#' . $month . ' (\d{1,2})(st|nd|rd|th)?#u';
     360                                $months[ $key ] = '#\b' . preg_quote( $month, '#' ) . ' (\d{1,2})(st|nd|rd|th)?\b#u';
    356361                        }
    357362
  • branches/5.3/tests/phpunit/tests/functions/maybeDeclineDate.php

    r45555 r46863  
    3838        /**
    3939         * @ticket 36790
     40         * @ticket 37411
     41         * @ticket 48606
    4042         * @dataProvider data_wp_maybe_decline_date
    4143         */
     
    7274                        array( 'ru_RU', 'Январь 1st 2016', '1 января 2016' ),
    7375                        array( 'ru_RU', 'Январь 1 2016', '1 января 2016' ),
     76                        array( 'ru_RU', 'Январь 1 16', '1 января 16' ),
     77                        array( 'ru_RU', 'Суббота, 19 Январь 2019 10:50', 'Суббота, 19 января 2019 10:50' ),
    7478                        array( 'pl_PL', '1 Styczeń', '1 stycznia' ),
    7579                        array( 'hr', '1. Siječanj', '1. siječnja' ),
     
    7781                        array( 'cs_CZ', '1. Červen', '1. června' ),
    7882                        array( 'cs_CZ', '1. Červenec', '1. července' ),
     83                        array( 'it_IT', 'Lundeì 11 Novembre 2019', 'Lundeì 11 Novembre 2019' ),
     84                        array( 'el', 'Σάββατο, 19 Ιανουάριος 2019 10:50', 'Σάββατο, 19 Ιανουαρίου 2019 10:50' ),
    7985                );
    8086        }
     
    117123                                break;
    118124
     125                        case 'it_IT':
     126                                $months = array(
     127                                        'month'          => array( 'Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre' ),
     128                                        'month_genitive' => array( 'Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre' ),
     129                                );
     130                                break;
     131
     132                        case 'el':
     133                                $months = array(
     134                                        'month'          => array( 'Ιανουάριος', 'Φεβρουάριος', 'Μάρτιος', 'Απρίλιος', 'Μάιος', 'Ιούνιος', 'Ιούλιος', 'Αύγουστος', 'Σεπτέμβριος', 'Οκτώβριος', 'Νοέμβριος', 'Δεκέμβριος' ),
     135                                        'month_genitive' => array( 'Ιανουαρίου', 'Φεβρουαρίου', 'Μαρτίου', 'Απριλίου', 'Μαΐου', 'Ιουνίου', 'Ιουλίου', 'Αυγούστου', 'Σεπτεμβρίου', 'Οκτωβρίου', 'Νοεμβρίου', 'Δεκεμβρίου' ),
     136                                );
     137                                break;
     138
    119139                        default:
    120140                                $months = array(
Note: See TracChangeset for help on using the changeset viewer.