Make WordPress Core

Changeset 27344


Ignore:
Timestamp:
03/01/2014 09:44:43 PM (10 years ago)
Author:
nacin
Message:

Strip backslashes, not just forward slashes, from untrailingslashit().

trailingslashit() will now remove any forward or backslashes from the end of a string before appending a forward slash.

props knutsp, willmot.
fixes #22267.

Location:
trunk
Files:
3 edited

Legend:

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

    r27284 r27344  
    14831483 * Appends a trailing slash.
    14841484 *
    1485  * Will remove trailing slash if it exists already before adding a trailing
    1486  * slash. This prevents double slashing a string or path.
     1485 * Will remove trailing forward and backslashes if it exists already before adding
     1486 * a trailing forward slash. This prevents double slashing a string or path.
    14871487 *
    14881488 * The primary use of this is for paths and thus should be used for paths. It is
     
    14901490 *
    14911491 * @since 1.2.0
    1492  * @uses untrailingslashit() Unslashes string if it was slashed already.
    14931492 *
    14941493 * @param string $string What to add the trailing slash to.
    14951494 * @return string String with trailing slash added.
    14961495 */
    1497 function trailingslashit($string) {
    1498     return untrailingslashit($string) . '/';
    1499 }
    1500 
    1501 /**
    1502  * Removes trailing slash if it exists.
     1496function trailingslashit( $string ) {
     1497    return untrailingslashit( $string ) . '/';
     1498}
     1499
     1500/**
     1501 * Removes trailing forward slashes and backslashes if they exist.
    15031502 *
    15041503 * The primary use of this is for paths and thus should be used for paths. It is
     
    15071506 * @since 2.2.0
    15081507 *
    1509  * @param string $string What to remove the trailing slash from.
    1510  * @return string String without the trailing slash.
    1511  */
    1512 function untrailingslashit($string) {
    1513     return rtrim($string, '/');
     1508 * @param string $string What to remove the trailing slashes from.
     1509 * @return string String without the trailing slashes.
     1510 */
     1511function untrailingslashit( $string ) {
     1512    return rtrim( $string, '/\\' );
    15141513}
    15151514
  • trunk/src/wp-includes/functions.php

    r27272 r27344  
    14561456
    14571457    if ( $temp )
    1458         return trailingslashit( rtrim( $temp, '\\' ) );
     1458        return trailingslashit( $temp );
    14591459
    14601460    if ( function_exists('sys_get_temp_dir') ) {
    14611461        $temp = sys_get_temp_dir();
    14621462        if ( @is_dir( $temp ) && wp_is_writable( $temp ) )
    1463             return trailingslashit( rtrim( $temp, '\\' ) );
     1463            return trailingslashit( $temp );
    14641464    }
    14651465
    14661466    $temp = ini_get('upload_tmp_dir');
    14671467    if ( @is_dir( $temp ) && wp_is_writable( $temp ) )
    1468         return trailingslashit( rtrim( $temp, '\\' ) );
     1468        return trailingslashit( $temp );
    14691469
    14701470    $temp = WP_CONTENT_DIR . '/';
  • trunk/tests/phpunit/tests/formatting/Slashit.php

    r25002 r27344  
    2222    }
    2323
     24    /**
     25     * @ticket 22267
     26     */
     27    function test_removes_trailing_backslashes() {
     28        $this->assertEquals("a", untrailingslashit("a\\"));
     29        $this->assertEquals("a", untrailingslashit("a\\\\\\\\"));
     30    }
     31
     32    /**
     33     * @ticket 22267
     34     */
     35    function test_removes_trailing_mixed_slashes() {
     36        $this->assertEquals("a", untrailingslashit("a/\\"));
     37        $this->assertEquals("a", untrailingslashit("a\\/\\///\\\\//"));
     38    }
     39
    2440    function test_adds_trailing_slash() {
    2541        $this->assertEquals("a/", trailingslashit("a"));
     
    2945        $this->assertEquals("a/", trailingslashit("a/"));
    3046    }
     47
     48    /**
     49     * @ticket 22267
     50     */
     51    function test_converts_trailing_backslash_to_slash_if_one_exists() {
     52        $this->assertEquals("a/", trailingslashit("a\\"));
     53    }
    3154}
Note: See TracChangeset for help on using the changeset viewer.