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'; + } }