You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ma...@apache.org on 2013/01/09 03:11:35 UTC

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

Updated Branches:
  refs/heads/master c130396d4 -> a1cfe87f1


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

Guarding against a null string being passed into FileUtils.getMimeType()


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/a1cfe87f
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/a1cfe87f
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/a1cfe87f

Branch: refs/heads/master
Commit: a1cfe87f1e55919a246478d981fecde72b038a02
Parents: c130396
Author: Simon MacDonald <si...@gmail.com>
Authored: Tue Jan 8 21:10:41 2013 -0500
Committer: Simon MacDonald <si...@gmail.com>
Committed: Tue Jan 8 21:10:50 2013 -0500

----------------------------------------------------------------------
 framework/src/org/apache/cordova/FileUtils.java |   20 ++++++++++-------
 1 files changed, 12 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/a1cfe87f/framework/src/org/apache/cordova/FileUtils.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/FileUtils.java b/framework/src/org/apache/cordova/FileUtils.java
index 5694b3d..aa695ac 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 "";
         }
     }