diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
index 7db3bbafd9..f8255dd262 100644
a
|
b
|
function wp_date( $format, $timestamp = null, $timezone = null ) { |
254 | 254 | for ( $i = 0; $i < $format_length; $i ++ ) { |
255 | 255 | switch ( $format[ $i ] ) { |
256 | 256 | 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' ); |
258 | 258 | break; |
259 | 259 | case 'F': |
260 | | $new_format .= backslashit( $month ); |
| 260 | $new_format .= addcslashes( $month, '\\A..Za..z' ); |
261 | 261 | break; |
262 | 262 | case 'l': |
263 | | $new_format .= backslashit( $weekday ); |
| 263 | $new_format .= addcslashes( $weekday, '\\A..Za..z' ); |
264 | 264 | break; |
265 | 265 | 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' ); |
267 | 267 | break; |
268 | 268 | 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' ); |
270 | 270 | break; |
271 | 271 | 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' ); |
273 | 273 | break; |
274 | 274 | case '\\': |
275 | 275 | $new_format .= $format[ $i ]; |
diff --git a/tests/phpunit/tests/date/wpDate.php b/tests/phpunit/tests/date/wpDate.php
index d3fb58aba2..01145c82c4 100644
a
|
b
|
|
6 | 6 | */ |
7 | 7 | class Tests_Date_WP_Date extends WP_UnitTestCase { |
8 | 8 | |
| 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 | |
9 | 28 | /** |
10 | 29 | * @ticket 28636 |
11 | 30 | */ |
12 | 31 | public function test_should_return_false_on_invalid_timestamp() { |
13 | 32 | $this->assertFalse( wp_date( DATE_RFC3339, 'invalid' ) ); |
14 | 33 | } |
| 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 | } |
15 | 63 | } |