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.

Built from https://develop.svn.wordpress.org/trunk@27344


git-svn-id: http://core.svn.wordpress.org/trunk@27196 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2014-03-01 21:45:15 +00:00
parent 482856e2e1
commit 580b05ae5d
2 changed files with 12 additions and 13 deletions

View File

@ -1482,35 +1482,34 @@ function backslashit($string) {
/** /**
* Appends a trailing slash. * Appends a trailing slash.
* *
* Will remove trailing slash if it exists already before adding a trailing * Will remove trailing forward and backslashes if it exists already before adding
* slash. This prevents double slashing a string or path. * a trailing forward slash. This prevents double slashing a string or path.
* *
* The primary use of this is for paths and thus should be used for paths. It is * The primary use of this is for paths and thus should be used for paths. It is
* not restricted to paths and offers no specific path support. * not restricted to paths and offers no specific path support.
* *
* @since 1.2.0 * @since 1.2.0
* @uses untrailingslashit() Unslashes string if it was slashed already.
* *
* @param string $string What to add the trailing slash to. * @param string $string What to add the trailing slash to.
* @return string String with trailing slash added. * @return string String with trailing slash added.
*/ */
function trailingslashit($string) { function trailingslashit( $string ) {
return untrailingslashit($string) . '/'; return untrailingslashit( $string ) . '/';
} }
/** /**
* Removes trailing slash if it exists. * Removes trailing forward slashes and backslashes if they exist.
* *
* The primary use of this is for paths and thus should be used for paths. It is * The primary use of this is for paths and thus should be used for paths. It is
* not restricted to paths and offers no specific path support. * not restricted to paths and offers no specific path support.
* *
* @since 2.2.0 * @since 2.2.0
* *
* @param string $string What to remove the trailing slash from. * @param string $string What to remove the trailing slashes from.
* @return string String without the trailing slash. * @return string String without the trailing slashes.
*/ */
function untrailingslashit($string) { function untrailingslashit( $string ) {
return rtrim($string, '/'); return rtrim( $string, '/\\' );
} }
/** /**

View File

@ -1455,17 +1455,17 @@ function get_temp_dir() {
return trailingslashit(WP_TEMP_DIR); return trailingslashit(WP_TEMP_DIR);
if ( $temp ) if ( $temp )
return trailingslashit( rtrim( $temp, '\\' ) ); return trailingslashit( $temp );
if ( function_exists('sys_get_temp_dir') ) { if ( function_exists('sys_get_temp_dir') ) {
$temp = sys_get_temp_dir(); $temp = sys_get_temp_dir();
if ( @is_dir( $temp ) && wp_is_writable( $temp ) ) if ( @is_dir( $temp ) && wp_is_writable( $temp ) )
return trailingslashit( rtrim( $temp, '\\' ) ); return trailingslashit( $temp );
} }
$temp = ini_get('upload_tmp_dir'); $temp = ini_get('upload_tmp_dir');
if ( @is_dir( $temp ) && wp_is_writable( $temp ) ) if ( @is_dir( $temp ) && wp_is_writable( $temp ) )
return trailingslashit( rtrim( $temp, '\\' ) ); return trailingslashit( $temp );
$temp = WP_CONTENT_DIR . '/'; $temp = WP_CONTENT_DIR . '/';
if ( is_dir( $temp ) && wp_is_writable( $temp ) ) if ( is_dir( $temp ) && wp_is_writable( $temp ) )