--- wp-includes/post.php
+++ wp-includes/post.php
@@ -3560,6 +3560,17 @@
 	return update_post_meta( $post->ID, '_wp_attachment_metadata', $data);
 }
 
+
+function _wp_get_url_from_filesystem_path($path) {
+  $filesystem_elements = explode('/',$path);
+  $url_elements = array();
+  foreach($filesystem_elements as $link) {
+	$url_elements[] = rawurlencode($link);
+  }
+  return implode('/',$url_elements);
+}
+
+
 /**
  * Retrieve the URL for an attachment.
  *
@@ -3576,12 +3587,16 @@
 	$url = '';
 	if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true) ) { //Get attached file
 		if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { //Get upload directory
-			if ( 0 === strpos($file, $uploads['basedir']) ) //Check that the upload base exists in the file location
-				$url = str_replace($uploads['basedir'], $uploads['baseurl'], $file); //replace file location with url location
-			elseif ( false !== strpos($file, 'wp-content/uploads') )
-				$url = $uploads['baseurl'] . substr( $file, strpos($file, 'wp-content/uploads') + 18 );
-			else
-				$url = $uploads['baseurl'] . "/$file"; //Its a newly uploaded file, therefor $file is relative to the basedir.
+			if ( 0 === strpos($file, $uploads['basedir']) ) { //Check that the upload base exists in the file location
+				$relative_path = substr($file,strlen($uploads['basedir'])+1);
+			}
+			elseif ( false !== strpos($file, 'wp-content/uploads') ) {
+				$relative_path = substr($file,strpos($file, 'wp-content/uploads') + 19 );
+			}
+			else {
+				$relative_path = $file;
+			}
+			$url = $uploads['baseurl'] . "/" . _wp_get_url_from_filesystem_path($relative_path);
 		}
 	}
 
