CB-2093: NullPointerException when attaching image from Gallery that contains spaces in the path

Guarding against a null string being passed into FileUtils.getMimeType()
This commit is contained in:
Simon MacDonald 2013-01-08 21:10:41 -05:00
parent c130396d4e
commit a1cfe87f1e

View File

@ -1019,15 +1019,19 @@ public class FileUtils extends CordovaPlugin {
* @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 "";
}
}