diff --git src/wp-includes/class-wp-theme.php src/wp-includes/class-wp-theme.php
index 8b3661a..f161a63 100644
--- src/wp-includes/class-wp-theme.php
+++ 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 tests/phpunit/data/themedir1/page-templates/38766/no-trailing-period-post-types.php tests/phpunit/data/themedir1/page-templates/38766/no-trailing-period-post-types.php
new file mode 100644
index 0000000..2b68671
--- /dev/null
+++ tests/phpunit/data/themedir1/page-templates/38766/no-trailing-period-post-types.php
@@ -0,0 +1,5 @@
+<?php
+/*
+   Template Name: No Trailing Period
+   Template Post Type: period, full-stop
+ */
diff --git tests/phpunit/data/themedir1/page-templates/38766/tilde-post-types.php tests/phpunit/data/themedir1/page-templates/38766/tilde-post-types.php
new file mode 100644
index 0000000..fd1a8ec
--- /dev/null
+++ tests/phpunit/data/themedir1/page-templates/38766/tilde-post-types.php
@@ -0,0 +1,7 @@
+<?php
+/*
+   Template Name: Tilde in Post Type.
+   Template Post Type: period, full~stop
+
+   This template should be applied to the `period` post type and ignored by the `full-stop` post type.
+ */
diff --git tests/phpunit/data/themedir1/page-templates/38766/trailing-comma-post-types.php tests/phpunit/data/themedir1/page-templates/38766/trailing-comma-post-types.php
new file mode 100644
index 0000000..9069f54
--- /dev/null
+++ tests/phpunit/data/themedir1/page-templates/38766/trailing-comma-post-types.php
@@ -0,0 +1,5 @@
+<?php
+/*
+   Template Name: Trailing Comma,
+   Template Post Type: period, full-stop,
+ */
diff --git tests/phpunit/data/themedir1/page-templates/38766/trailing-period-post-types.php tests/phpunit/data/themedir1/page-templates/38766/trailing-period-post-types.php
new file mode 100644
index 0000000..4c703bb
--- /dev/null
+++ tests/phpunit/data/themedir1/page-templates/38766/trailing-period-post-types.php
@@ -0,0 +1,5 @@
+<?php
+/*
+   Template Name: Trailing Period.
+   Template Post Type: period, full-stop.
+ */
diff --git tests/phpunit/data/themedir1/page-templates/38766/trailing-period-whitespace-post-types.php tests/phpunit/data/themedir1/page-templates/38766/trailing-period-whitespace-post-types.php
new file mode 100644
index 0000000..aeb6688
--- /dev/null
+++ tests/phpunit/data/themedir1/page-templates/38766/trailing-period-whitespace-post-types.php
@@ -0,0 +1,5 @@
+<?php
+/*
+   Template Name: Trailing Period, White Space.
+   Template Post Type: period, full-stop. 	
+ */
diff --git tests/phpunit/data/themedir1/page-templates/38766/trailing-whitespace-period-post-types.php tests/phpunit/data/themedir1/page-templates/38766/trailing-whitespace-period-post-types.php
new file mode 100644
index 0000000..2b123fa
--- /dev/null
+++ tests/phpunit/data/themedir1/page-templates/38766/trailing-whitespace-period-post-types.php
@@ -0,0 +1,5 @@
+<?php
+/*
+   Template Name: Trailing White Space, Period.
+   Template Post Type: period, full-stop 	 .
+ */
diff --git tests/phpunit/tests/admin/includesTheme.php tests/phpunit/tests/admin/includesTheme.php
index 5319006..522615c 100644
--- tests/phpunit/tests/admin/includesTheme.php
+++ tests/phpunit/tests/admin/includesTheme.php
@@ -87,6 +87,32 @@ class Tests_Admin_includesTheme extends WP_UnitTestCase {
 	}
 
 	/**
+	 * @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
 	 */
 	function test_page_templates_child_theme() {
