From a1cfe87f1e55919a246478d981fecde72b038a02 Mon Sep 17 00:00:00 2001 From: Simon MacDonald Date: Tue, 8 Jan 2013 21:10:41 -0500 Subject: [PATCH] CB-2093: NullPointerException when attaching image from Gallery that contains spaces in the path Guarding against a null string being passed into FileUtils.getMimeType() --- .../src/org/apache/cordova/FileUtils.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/framework/src/org/apache/cordova/FileUtils.java b/framework/src/org/apache/cordova/FileUtils.java index 5694b3d0..aa695acf 100755 --- a/framework/src/org/apache/cordova/FileUtils.java +++ b/framework/src/org/apache/cordova/FileUtils.java @@ -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 ""; } }