Formatting: In `sanitize_title_with_dashes()`, convert forward slash to hyphen on save.

Props corvidism, jtsternberg, GhostToast, alxndr.
Fixes #10792.

git-svn-id: https://develop.svn.wordpress.org/trunk@41318 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2017-08-25 23:27:55 +00:00
parent 481e055db2
commit 93dd8e28be
2 changed files with 13 additions and 0 deletions

View File

@ -2000,6 +2000,8 @@ function sanitize_title_with_dashes( $title, $raw_title = '', $context = 'displa
$title = str_replace( array( '%c2%a0', '%e2%80%93', '%e2%80%94' ), '-', $title );
// Convert nbsp, ndash and mdash HTML entities to hyphens
$title = str_replace( array( ' ', ' ', '–', '–', '—', '—' ), '-', $title );
// Convert forward slash to hyphen
$title = str_replace( '/', '-', $title );
// Strip these characters entirely
$title = str_replace( array(

View File

@ -108,6 +108,17 @@ class Tests_Formatting_SanitizeTitleWithDashes extends WP_UnitTestCase {
$this->assertEquals("just-a-slug", sanitize_title_with_dashes("Just ™ a Slug", '', 'save'));
}
/**
* @ticket 10792
*/
function test_replaces_forward_slash() {
$this->assertEquals("songs-by-lennon-mccartney", sanitize_title_with_dashes("songs by Lennon/McCartney", '', 'save'));
$this->assertEquals("songs-by-lennon-mccartney", sanitize_title_with_dashes("songs by Lennon//McCartney", '', 'save'));
$this->assertEquals("songs-by-lennon-mccartney", sanitize_title_with_dashes("songs by Lennon///McCartney", '', 'save'));
$this->assertEquals("songs-by-lennon-mccartney", sanitize_title_with_dashes("songs by Lennon/-McCartney", '', 'save'));
$this->assertEquals("songs-by-lennon-mccartney", sanitize_title_with_dashes("//songs by Lennon/McCartney", '', 'save'));
}
/**
* @ticket 19820
*/