Index: src/wp-admin/includes/file.php
===================================================================
--- src/wp-admin/includes/file.php	(revision 29203)
+++ src/wp-admin/includes/file.php	(working copy)
@@ -471,10 +471,6 @@
 
 	$filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );
 
-	// Strip the query strings.
-	$filename = str_replace('?','-', $filename);
-	$filename = str_replace('&','-', $filename);
-
 	// Move the file to the uploads dir
 	$new_file = $uploads['path'] . "/$filename";
 	if ( false === @ rename( $file['tmp_name'], $new_file ) ) {
Index: src/wp-includes/formatting.php
===================================================================
--- src/wp-includes/formatting.php	(revision 29203)
+++ src/wp-includes/formatting.php	(working copy)
@@ -1049,6 +1049,7 @@
 	$special_chars = apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw );
 	$filename = preg_replace( "#\x{00a0}#siu", ' ', $filename );
 	$filename = str_replace($special_chars, '', $filename);
+	$filename = str_replace( array( '%20', '+' ), '-', $filename );
 	$filename = preg_replace('/[\s-]+/', '-', $filename);
 	$filename = trim($filename, '.-_');
 
Index: tests/phpunit/tests/formatting/SanitizeFileName.php
===================================================================
--- tests/phpunit/tests/formatting/SanitizeFileName.php	(revision 29203)
+++ tests/phpunit/tests/formatting/SanitizeFileName.php	(working copy)
@@ -19,6 +19,24 @@
 		$this->assertEquals( 'testtest', sanitize_file_name( $string ) );
 	}
 
+	/**
+	 * Test that spaces are correctly replaced with dashes.
+	 *
+	 * @ticket 16330
+	 */
+	function test_replace_spaces() {
+		$urls = array(
+			'unencoded space.png'   => 'unencoded-space.png',
+			'encoded%20space.jpg'   => 'encoded-space.jpg',
+			'plus+space.jpg'        => 'plus-space.jpg',
+			'multi %20 +space.png'   => 'multi-space.png',
+		);
+
+		foreach( $urls as $test => $expected ) {
+			$this->assertEquals( $expected, sanitize_file_name( $test ) );
+		}
+	}
+
 	function test_replaces_any_number_of_hyphens_with_one_hyphen() {
 		$this->assertEquals("a-t-t", sanitize_file_name("a----t----t"));
 	}
