diff --git a/src/wp-includes/formatting.php b/src/wp-includes/formatting.php index bd2d349fa20c1..cf2bbc8c7a1d6 100644 --- a/src/wp-includes/formatting.php +++ b/src/wp-includes/formatting.php @@ -2284,6 +2284,9 @@ function sanitize_title_with_dashes( $title, $raw_title = '', $context = 'displa // Restore octets. $title = preg_replace( '|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title ); + // Convert multiplication sign and times entities to 'x'. + $title = str_replace( array( '×', '×', '×' ), 'x', $title ); + if ( wp_is_valid_utf8( $title ) ) { if ( function_exists( 'mb_strtolower' ) ) { $title = mb_strtolower( $title, 'UTF-8' ); diff --git a/tests/phpunit/tests/formatting/sanitizeTitleWithDashes.php b/tests/phpunit/tests/formatting/sanitizeTitleWithDashes.php index 8a2ee4f9d9fee..5292e2f202692 100644 --- a/tests/phpunit/tests/formatting/sanitizeTitleWithDashes.php +++ b/tests/phpunit/tests/formatting/sanitizeTitleWithDashes.php @@ -146,7 +146,39 @@ public function test_replaces_forward_slash() { * @ticket 19820 */ public function test_replaces_multiply_sign() { - $this->assertSame( '6x7-is-42', sanitize_title_with_dashes( '6×7 is 42', '', 'save' ) ); + $this->assertSame( '6x7-is-42', sanitize_title_with_dashes( '6×7 is 42', '', 'save' ), 'Multiplication sign (×) should be replaced with letter x' ); + } + + /** + * @ticket 64284 + */ + public function test_replaces_multiply_sign_with_spaces() { + $this->assertSame( 'iphone-12-x-256gb', sanitize_title_with_dashes( 'iPhone 12 × 256GB', '', 'save' ), 'Product title with multiplication sign and spaces should convert × to x' ); + $this->assertSame( 'screen-1920-x-1080', sanitize_title_with_dashes( 'Screen 1920 × 1080', '', 'save' ), 'Screen dimensions with multiplication sign should convert × to x' ); + } + + /** + * @ticket 64284 + */ + public function test_replaces_times_html_entity() { + $this->assertSame( '6x7-is-42', sanitize_title_with_dashes( '6×7 is 42', '', 'save' ), 'HTML entity × should be replaced with letter x' ); + $this->assertSame( 'product-5x10', sanitize_title_with_dashes( 'Product 5×10', '', 'save' ), 'HTML entity × without spaces should be replaced with letter x' ); + } + + /** + * @ticket 64284 + */ + public function test_replaces_times_numeric_entity() { + $this->assertSame( '3x4-equals-12', sanitize_title_with_dashes( '3×4 equals 12', '', 'save' ), 'Numeric HTML entity × should be replaced with letter x' ); + } + + /** + * @ticket 64284 + */ + public function test_replaces_multiply_sign_in_display_context() { + // Should work in display context too, not just 'save'. + $this->assertSame( '6x7', sanitize_title_with_dashes( '6×7', '', 'display' ), 'Multiplication sign should be replaced with x in display context' ); + $this->assertSame( 'testx', sanitize_title_with_dashes( 'test×', '' ), 'Multiplication sign should be replaced with x when context is not specified' ); } /**