diff --git a/src/wp-includes/class-wp-theme.php b/src/wp-includes/class-wp-theme.php index 8b3661a888..f161a63186 100644 --- a/src/wp-includes/class-wp-theme.php +++ b/src/wp-includes/class-wp-theme.php @@ -1038,7 +1038,7 @@ final class WP_Theme implements ArrayAccess { } foreach ( $types as $type ) { - $type = trim( $type ); + $type = sanitize_key( $type ); if ( ! isset( $post_templates[ $type ] ) ) { $post_templates[ $type ] = array(); } diff --git a/tests/phpunit/data/themedir1/page-templates/38766/no-trailing-period-post-types.php b/tests/phpunit/data/themedir1/page-templates/38766/no-trailing-period-post-types.php new file mode 100644 index 0000000000..2b6867109a --- /dev/null +++ b/tests/phpunit/data/themedir1/page-templates/38766/no-trailing-period-post-types.php @@ -0,0 +1,5 @@ +assertEquals( array(), get_page_templates( null, 'bar' ) ); } + /** + * @ticket 38766 + */ + function test_page_templates_for_post_types_with_trailing_periods() { + $theme = wp_get_theme( 'page-templates' ); + $this->assertNotEmpty( $theme ); + + switch_theme( $theme['Template'], $theme['Stylesheet'] ); + + $this->assertEqualSetsWithIndex( array( + 'No Trailing Period' => '38766/no-trailing-period-post-types.php', + 'Trailing Period.' => '38766/trailing-period-post-types.php', + 'Trailing Comma,' => '38766/trailing-comma-post-types.php', + 'Trailing Period, White Space.' => '38766/trailing-period-whitespace-post-types.php', + 'Trailing White Space, Period.' => '38766/trailing-whitespace-period-post-types.php', + 'Tilde in Post Type.' => '38766/tilde-post-types.php', + ), get_page_templates( null, 'period' ) ); + $this->assertEqualSetsWithIndex( array( + 'No Trailing Period' => '38766/no-trailing-period-post-types.php', + 'Trailing Period.' => '38766/trailing-period-post-types.php', + 'Trailing Comma,' => '38766/trailing-comma-post-types.php', + 'Trailing Period, White Space.' => '38766/trailing-period-whitespace-post-types.php', + 'Trailing White Space, Period.' => '38766/trailing-whitespace-period-post-types.php', + ), get_page_templates( null, 'full-stop' ) ); + } + /** * @ticket 38696 */