Index: src/wp-includes/canonical.php
===================================================================
--- src/wp-includes/canonical.php	(revision 39927)
+++ src/wp-includes/canonical.php	(working copy)
@@ -567,7 +567,9 @@
 		if ( ! empty( $parsed_url['port'] ) ) {
 			$url .= ':' . $parsed_url['port'];
 		}
-		$url .= $parsed_url['path'];
+		if ( ! empty( $parsed_url['path'] ) ) {
+			$url .= $parsed_url['path'];
+		}
 		if ( ! empty( $parsed_url['query'] ) ) {
 			$url .= '?' . $parsed_url['query'];
 		}
Index: src/wp-includes/functions.php
===================================================================
--- src/wp-includes/functions.php	(revision 39927)
+++ src/wp-includes/functions.php	(working copy)
@@ -2235,6 +2235,15 @@
 	$type = false;
 	$ext = false;
 
+	// Strip query args and fragment from filename to reveal extension.
+	$query_pos = strpos( $filename, '?' );
+
+	if ( false !== $query_pos ) {
+		$filename = substr_replace( $filename, '', $query_pos );
+	}
+
+	$filename = strip_fragment_from_url( $filename );
+
 	foreach ( $mimes as $ext_preg => $mime_match ) {
 		$ext_preg = '!\.(' . $ext_preg . ')$!i';
 		if ( preg_match( $ext_preg, $filename, $ext_matches ) ) {
Index: tests/phpunit/tests/functions/wpCheckFiletype.php
===================================================================
--- tests/phpunit/tests/functions/wpCheckFiletype.php	(nonexistent)
+++ tests/phpunit/tests/functions/wpCheckFiletype.php	(working copy)
@@ -0,0 +1,37 @@
+<?php
+
+/**
+ * Tests for wp_check_filetype()
+ *
+ * @group functions.php
+ */
+class Tests_Functions_WP_Check_Filetype extends WP_UnitTestCase {
+
+	public function _data_url_filetypes() {
+		return array(
+			array( null, false ),
+			array( '', false ),
+			array( ' ', false ),
+			array( 'http://example.com', false ),
+			array( 'http://example.com/', false ),
+			array( 'http://example.com/wibble', false ),
+			array( 'http://example.com/wibble/', false ),
+			array( 'http://example.com/wibble.wobble', false ),
+			array( 'http://example.com/wibble.mp3', 'mp3' ),
+			array( 'http://example.com/wibble.mp3#wobble', 'mp3' ),
+			array( 'http://example.com/wibble.mp3?wobble=true', 'mp3' ),
+			array( 'http://example.com/wibble.mp3?wobble=true#wobble', 'mp3' ),
+		);
+	}
+
+	/**
+	 * @dataProvider _data_url_filetypes
+	 *
+	 * @param $url
+	 * @param $expected
+	 */
+	public function test_url_ext( $url, $expected ) {
+		$filetype = wp_check_filetype( $url );
+		$this->assertSame( $expected, $filetype['ext'] );
+	}
+}
