Make WordPress Core

Changeset 46569


Ignore:
Timestamp:
10/22/2019 05:29:02 PM (7 years ago)
Author:
SergeyBiryukov
Message:

Date/Time: Make sure wp_date() does not unnecessarily escape localized numbers, but keeps localized slashes.

Props Rarst, tmatsuur, remcotolsma, peterwilsoncc.
Reviewed by peterwilsoncc.
Fixes #48319.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r46476 r46569  
    255255                        switch ( $format[ $i ] ) {
    256256                                case 'D':
    257                                         $new_format .= backslashit( $wp_locale->get_weekday_abbrev( $weekday ) );
     257                                        $new_format .= addcslashes( $wp_locale->get_weekday_abbrev( $weekday ), '\\A..Za..z' );
    258258                                        break;
    259259                                case 'F':
    260                                         $new_format .= backslashit( $month );
     260                                        $new_format .= addcslashes( $month, '\\A..Za..z' );
    261261                                        break;
    262262                                case 'l':
    263                                         $new_format .= backslashit( $weekday );
     263                                        $new_format .= addcslashes( $weekday, '\\A..Za..z' );
    264264                                        break;
    265265                                case 'M':
    266                                         $new_format .= backslashit( $wp_locale->get_month_abbrev( $month ) );
     266                                        $new_format .= addcslashes( $wp_locale->get_month_abbrev( $month ), '\\A..Za..z' );
    267267                                        break;
    268268                                case 'a':
    269                                         $new_format .= backslashit( $wp_locale->get_meridiem( $datetime->format( 'a' ) ) );
     269                                        $new_format .= addcslashes( $wp_locale->get_meridiem( $datetime->format( 'a' ) ), '\\A..Za..z' );
    270270                                        break;
    271271                                case 'A':
    272                                         $new_format .= backslashit( $wp_locale->get_meridiem( $datetime->format( 'A' ) ) );
     272                                        $new_format .= addcslashes( $wp_locale->get_meridiem( $datetime->format( 'A' ) ), '\\A..Za..z' );
    273273                                        break;
    274274                                case '\\':
  • trunk/tests/phpunit/tests/date/wpDate.php

    r45914 r46569  
    77class Tests_Date_WP_Date extends WP_UnitTestCase {
    88
     9        /** @var WP_Locale */
     10        private $wp_locale_original;
     11
     12        public function setUp() {
     13                global $wp_locale;
     14
     15                parent::setUp();
     16
     17                $this->wp_locale_original = clone $wp_locale;
     18        }
     19
     20        public function tearDown() {
     21                global $wp_locale;
     22
     23                $wp_locale = $this->wp_locale_original;
     24
     25                parent::tearDown();
     26        }
     27
    928        /**
    1029         * @ticket 28636
     
    1332                $this->assertFalse( wp_date( DATE_RFC3339, 'invalid' ) );
    1433        }
     34
     35        /**
     36         * @ticket 48319
     37         */
     38        public function test_should_not_escape_localized_numbers() {
     39                global $wp_locale;
     40
     41                $wp_locale->month = array( 10 => '10月' );
     42
     43                $utc      = new DateTimeZone( 'UTC' );
     44                $datetime = new DateTimeImmutable( '2019-10-17', $utc );
     45
     46                $this->assertEquals( '10月', wp_date( 'F', $datetime->getTimestamp(), $utc ) );
     47        }
     48
     49        /**
     50         * @ticket 48319
     51         */
     52        public function test_should_keep_localized_slashes() {
     53                global $wp_locale;
     54
     55                $string           = 'A \ B';
     56                $wp_locale->month = array( 10 => $string );
     57
     58                $utc      = new DateTimeZone( 'UTC' );
     59                $datetime = new DateTimeImmutable( '2019-10-17', $utc );
     60
     61                $this->assertEquals( $string, wp_date( 'F', $datetime->getTimestamp(), $utc ) );
     62        }
    1563}
Note: See TracChangeset for help on using the changeset viewer.