Skip to content

Commit 7d826c0

Browse files
committed
Formatting: Replace non-breaking hyphens (U+2011) with hyphens in sanitize_title_with_dashes().
Developed in #10204 Follow-up to [18705], [36775]. Props patpiwo, westonruter, dmsnell. See #31790, #10797. Fixes #64089. git-svn-id: https://develop.svn.wordpress.org/trunk@61061 602fd350-edb4-49c9-b593-d223f7449a82
1 parent abaf4d3 commit 7d826c0

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/wp-includes/formatting.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,10 +2294,10 @@ function sanitize_title_with_dashes( $title, $raw_title = '', $context = 'displa
22942294
$title = strtolower( $title );
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 );
23032303

tests/phpunit/tests/formatting/sanitizeTitleWithDashes.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ public function test_replaces_ndash_mdash_entities() {
8585
$this->assertSame( 'do-the-dash', sanitize_title_with_dashes( 'Do — the — Dash', '', 'save' ) );
8686
}
8787

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' ) );
100+
}
101+
88102
public function test_replaces_iexcel_iquest() {
89103
$this->assertSame( 'just-a-slug', sanitize_title_with_dashes( 'Just ¡a Slug', '', 'save' ) );
90104
$this->assertSame( 'just-a-slug', sanitize_title_with_dashes( 'Just a Slug¿', '', 'save' ) );

0 commit comments

Comments
 (0)