Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/wp-includes/formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -2287,6 +2287,14 @@ 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'.
$times_replacements = array( '×', '×', '×' );
if ( 'save' === $context ) {
$times_replacements[] = '%c3%97';
$times_replacements[] = '%C3%97';
}
$title = str_replace( $times_replacements, 'x', $title );

if ( wp_is_valid_utf8( $title ) ) {
if ( function_exists( 'mb_strtolower' ) ) {
$title = mb_strtolower( $title, 'UTF-8' );
Expand Down Expand Up @@ -2382,9 +2390,6 @@ function sanitize_title_with_dashes( $title, $raw_title = '', $context = 'displa
'-',
$title
);

// Convert &times to 'x'.
$title = str_replace( '%c3%97', 'x', $title );
}

// Remove HTML entities.
Expand Down
42 changes: 41 additions & 1 deletion tests/phpunit/tests/formatting/sanitizeTitleWithDashes.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,47 @@ 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' );
}

/**
* @ticket 64284
*/
public function test_replaces_url_encoded_multiply_sign() {
$this->assertSame( 'x', sanitize_title_with_dashes( '%c3%97', '', 'save' ), 'URL-encoded multiplication sign (lowercase %c3%97) should be replaced with x in save context' );
$this->assertSame( 'x', sanitize_title_with_dashes( '%C3%97', '', 'save' ), 'URL-encoded multiplication sign (uppercase %C3%97) should be replaced with x in save context' );
}

/**
Expand Down
Loading