Make WordPress Core

Changeset 36775


Ignore:
Timestamp:
02/29/2016 04:41:03 AM (10 years ago)
Author:
SergeyBiryukov
Message:

Formatting: In sanitize_title_with_dashes(), convert &nbsp, &ndash, and &mdash HTML entities to hyphens on save.

Props polevaultweb for initial patch.
Fixes #31790.

Location:
trunk
Files:
2 edited

Legend:

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

    r36578 r36775  
    15851585
    15861586        $title = strtolower($title);
    1587         $title = preg_replace('/&.+?;/', '', $title); // kill entities
    1588         $title = str_replace('.', '-', $title);
    15891587
    15901588        if ( 'save' == $context ) {
    15911589                // Convert nbsp, ndash and mdash to hyphens
    15921590                $title = str_replace( array( '%c2%a0', '%e2%80%93', '%e2%80%94' ), '-', $title );
     1591                // Convert nbsp, ndash and mdash HTML entities to hyphens
     1592                $title = str_replace( array( ' ', ' ', '–', '–', '—', '—' ), '-', $title );
    15931593
    15941594                // Strip these characters entirely
     
    16121612                $title = str_replace( '%c3%97', 'x', $title );
    16131613        }
     1614
     1615        $title = preg_replace('/&.+?;/', '', $title); // kill entities
     1616        $title = str_replace('.', '-', $title);
    16141617
    16151618        $title = preg_replace('/[^%a-z0-9 _-]/', '', $title);
  • trunk/tests/phpunit/tests/formatting/SanitizeTitleWithDashes.php

    r30515 r36775  
    6464        }
    6565
     66        /**
     67         * @ticket 31790
     68         */
     69        function test_replaces_nbsp_entities() {
     70                $this->assertEquals("dont-break-the-space", sanitize_title_with_dashes("don't break the space", '', 'save'));
     71        }
     72
    6673        function test_replaces_ndash_mdash() {
    6774                $this->assertEquals("do-the-dash", sanitize_title_with_dashes("Do – the Dash", '', 'save'));
    6875                $this->assertEquals("do-the-dash", sanitize_title_with_dashes("Do the — Dash", '', 'save'));
     76        }
     77
     78        /**
     79         * @ticket 31790
     80         */
     81        function test_replaces_ndash_mdash_entities() {
     82                $this->assertEquals("do-the-dash", sanitize_title_with_dashes("Do – the – Dash", '', 'save'));
     83                $this->assertEquals("do-the-dash", sanitize_title_with_dashes("Do — the — Dash", '', 'save'));
    6984        }
    7085
Note: See TracChangeset for help on using the changeset viewer.