From c9531d6d670f3949a07500439a11f7c2a45f5243 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Tue, 25 Mar 2014 13:06:21 +0000 Subject: [PATCH] Encode spaces in get_template_directory_uri() and get_stylesheet_directory_uri(). props SergeyBiryukov. fixes #21969. git-svn-id: https://develop.svn.wordpress.org/trunk@27710 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/theme.php | 4 ++-- tests/phpunit/tests/theme/WPTheme.php | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index d643a9e289..8a675d44a9 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -187,7 +187,7 @@ function get_stylesheet_directory() { * @return string */ function get_stylesheet_directory_uri() { - $stylesheet = get_stylesheet(); + $stylesheet = str_replace( '%2F', '/', rawurlencode( get_stylesheet() ) ); $theme_root_uri = get_theme_root_uri( $stylesheet ); $stylesheet_dir_uri = "$theme_root_uri/$stylesheet"; @@ -318,7 +318,7 @@ function get_template_directory() { * @return string Template directory URI. */ function get_template_directory_uri() { - $template = get_template(); + $template = str_replace( '%2F', '/', rawurlencode( get_template() ) ); $theme_root_uri = get_theme_root_uri( $template ); $template_dir_uri = "$theme_root_uri/$template"; diff --git a/tests/phpunit/tests/theme/WPTheme.php b/tests/phpunit/tests/theme/WPTheme.php index 44cedfcb02..4dbad859d4 100644 --- a/tests/phpunit/tests/theme/WPTheme.php +++ b/tests/phpunit/tests/theme/WPTheme.php @@ -110,4 +110,22 @@ class Tests_Theme_WPTheme extends WP_UnitTestCase { $this->assertEquals( admin_url( 'customize.php?theme=theme+with+spaces' ), wp_customize_url( 'theme with spaces' ) ); } + /** + * @ticket 21969 + */ + function test_theme_uris_with_spaces() { + $callback = array( $this, 'filter_theme_with_spaces' ); + add_filter( 'stylesheet', $callback ); + add_filter( 'template', $callback ); + + $this->assertEquals( get_theme_root_uri() . '/subdir/theme%20with%20spaces', get_stylesheet_directory_uri() ); + $this->assertEquals( get_theme_root_uri() . '/subdir/theme%20with%20spaces', get_template_directory_uri() ); + + remove_filter( 'stylesheet', $callback ); + add_filter( 'template', $callback ); + } + + function filter_theme_with_spaces() { + return 'subdir/theme with spaces'; + } }