Make WordPress Core

Changeset 61061


Ignore:
Timestamp:
10/25/2025 06:22:07 PM (7 weeks ago)
Author:
westonruter
Message:

Formatting: Replace non-breaking hyphens (U+2011) with hyphens in sanitize_title_with_dashes().

Developed in https://github.com/WordPress/wordpress-develop/pull/10204

Follow-up to [18705], [36775].

Props patpiwo, westonruter, dmsnell.
See #31790, #10797.
Fixes #64089.

Location:
trunk
Files:
2 edited

Legend:

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

    r61053 r61061  
    22952295
    22962296    if ( 'save' === $context ) {
    2297         // Convert &nbsp, &ndash, and &mdash to hyphens.
    2298         $title = str_replace( array( '%c2%a0', '%e2%80%93', '%e2%80%94' ), '-', $title );
    2299         // Convert &nbsp, &ndash, and &mdash HTML entities to hyphens.
    2300         $title = str_replace( array( ' ', ' ', '–', '–', '—', '—' ), '-', $title );
     2297        // Convert &nbsp, non-breaking hyphen, &ndash, and &mdash to hyphens.
     2298        $title = str_replace( array( '%c2%a0', '%e2%80%91', '%e2%80%93', '%e2%80%94' ), '-', $title );
     2299        // Convert &nbsp, non-breaking hyphen, &ndash, and &mdash HTML entities to hyphens.
     2300        $title = str_replace( array( ' ', '‑', ' ', '–', '–', '—', '—' ), '-', $title );
    23012301        // Convert forward slash to hyphen.
    23022302        $title = str_replace( '/', '-', $title );
  • trunk/tests/phpunit/tests/formatting/sanitizeTitleWithDashes.php

    r54474 r61061  
    8484        $this->assertSame( 'do-the-dash', sanitize_title_with_dashes( 'Do – the – Dash', '', 'save' ) );
    8585        $this->assertSame( 'do-the-dash', sanitize_title_with_dashes( 'Do — the — Dash', '', 'save' ) );
     86    }
     87
     88    /**
     89     * @ticket 64089
     90     */
     91    public function test_replaces_non_breaking_hyphen() {
     92        $this->assertSame( 'do-the-dash', sanitize_title_with_dashes( 'Do‑the Dash', '', 'save' ) );
     93    }
     94
     95    /**
     96     * @ticket 64089
     97     */
     98    public function test_replaces_non_breaking_hyphen_entity() {
     99        $this->assertSame( 'do-the-dash', sanitize_title_with_dashes( 'Do ‑ the Dash', '', 'save' ) );
    86100    }
    87101
Note: See TracChangeset for help on using the changeset viewer.