Skip to content

Commit

Permalink
CB-2093: NullPointerException when attaching image from Gallery that …
Browse files Browse the repository at this point in the history
…contains spaces in the path

Guarding against a null string being passed into FileUtils.getMimeType()
  • Loading branch information
macdonst committed Jan 9, 2013
1 parent c130396 commit a1cfe87
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions framework/src/org/apache/cordova/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1019,15 +1019,19 @@ public String readAsDataURL(String filename, int start, int end) throws FileNotF
* @return a mime type
*/
public static String getMimeType(String filename) {
// Stupid bug in getFileExtensionFromUrl when the file name has a space
// So we need to replace the space with a url encoded %20
String url = filename.replace(" ", "%20");
MimeTypeMap map = MimeTypeMap.getSingleton();
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
if (extension.toLowerCase().equals("3ga")) {
return "audio/3gpp";
if (filename != null) {
// Stupid bug in getFileExtensionFromUrl when the file name has a space
// So we need to replace the space with a url encoded %20
String url = filename.replace(" ", "%20");
MimeTypeMap map = MimeTypeMap.getSingleton();
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
if (extension.toLowerCase().equals("3ga")) {
return "audio/3gpp";
} else {
return map.getMimeTypeFromExtension(extension);
}
} else {
return map.getMimeTypeFromExtension(extension);
return "";
}
}

Expand Down

0 comments on commit a1cfe87

Please sign in to comment.