Ticket #39768: 39768.2.diff
File 39768.2.diff, 2.6 KB (added by , 5 years ago) |
---|
-
src/wp-includes/media.php
4294 4294 $path = substr( $path, strlen( $dir['baseurl'] . '/' ) ); 4295 4295 } 4296 4296 4297 $sql = $wpdb->prepare( 4298 "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = %s", 4299 $path 4300 ); 4297 if ( $wpdb->has_cap( 'utf8mb4' ) ) { 4298 // Use case-sensitive query, if possible. 4299 $sql = $wpdb->prepare( 4300 "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = CONVERT( %s USING utf8mb4 ) COLLATE utf8mb4_bin", 4301 $path 4302 ); 4303 } else { 4304 $sql = $wpdb->prepare( 4305 "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = %s", 4306 $path 4307 ); 4308 } 4301 4309 4302 4310 $post_id = $wpdb->get_var( $sql ); 4303 4311 -
tests/phpunit/tests/media.php
1058 1058 $this->assertEquals( $attachment_id, attachment_url_to_postid( $image_url ) ); 1059 1059 } 1060 1060 1061 function test_attachment_url_to_postid_schemes() { 1061 /** 1062 * @ticket 33109 1063 */ 1064 function test_attachment_url_to_postid_with_different_scheme() { 1062 1065 $image_path = '2014/11/' . $this->img_name; 1063 1066 $attachment_id = self::factory()->attachment->create_object( 1064 1067 $image_path, … … 1069 1072 ) 1070 1073 ); 1071 1074 1072 /**1073 * @ticket 33109 Testing protocols not matching1074 */1075 1075 $image_url = 'https://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_path; 1076 1076 $this->assertEquals( $attachment_id, attachment_url_to_postid( $image_url ) ); 1077 1077 } 1078 1078 1079 /** 1080 * @ticket 39768 1081 */ 1082 function test_attachment_url_to_postid_should_be_case_sensitive() { 1083 global $wpdb; 1084 1085 if ( ! $wpdb->has_cap( 'utf8mb4' ) ) { 1086 $this->markTestSkipped( 'This test requires utf8mb4 support in MySQL.' ); 1087 } 1088 1089 $image_path = '2014/11/' . $this->img_name; 1090 $attachment_id = self::factory()->attachment->create_object( 1091 $image_path, 1092 0, 1093 array( 1094 'post_mime_type' => 'image/jpeg', 1095 'post_type' => 'attachment', 1096 ) 1097 ); 1098 1099 $image_path = '2014/11/' . ucfirst( $this->img_name ); 1100 $image_url = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_path; 1101 $this->assertNotEquals( $attachment_id, attachment_url_to_postid( $image_url ) ); 1102 } 1103 1079 1104 function test_attachment_url_to_postid_filtered() { 1080 1105 $image_path = '2014/11/' . $this->img_name; 1081 1106 $attachment_id = self::factory()->attachment->create_object(