summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Sandblad <andreas.sandblad@sonyericsson.com>2010-08-25 09:40:10 +0200
committerEddie Ringle <eddie.ringle@gmail.com>2010-12-19 14:38:01 -0500
commite3f452046f90d4043db4fb24c331a5444315185e (patch)
tree55d4ef58fa363d9d4c6790f536f476ad76ea3cd2
parent834550e45ea702dce20926577a809177b89a4572 (diff)
downloadandroid_packages_providers_DownloadProvider-e3f452046f90d4043db4fb24c331a5444315185e.zip
android_packages_providers_DownloadProvider-e3f452046f90d4043db4fb24c331a5444315185e.tar.gz
android_packages_providers_DownloadProvider-e3f452046f90d4043db4fb24c331a5444315185e.tar.bz2
Added support for downloading files with unicode characters
Currently only certain ASCII characters are allowed in a filename, all other characters are replaced with an underscore. This gives bad usability for foreign languages (e.g. japanese). This fix replaces the current regexp with a method which replaces only those characters unsafe to be used on VFAT filesystems (should work on most other filesystems as well). Change-Id: I114d47b4b35f28490e6b12493138355532fda499 Signed-off-by: Eddie Ringle <eddie.ringle@gmail.com>
-rw-r--r--src/com/android/providers/downloads/Helpers.java54
1 files changed, 52 insertions, 2 deletions
diff --git a/src/com/android/providers/downloads/Helpers.java b/src/com/android/providers/downloads/Helpers.java
index 06669fd..2b88512 100644
--- a/src/com/android/providers/downloads/Helpers.java
+++ b/src/com/android/providers/downloads/Helpers.java
@@ -324,8 +324,9 @@ public class Helpers {
filename = Constants.DEFAULT_DL_FILENAME;
}
- filename = filename.replaceAll("[^a-zA-Z0-9\\.\\-_]+", "_");
-
+ // The VFAT file system is assumed as target for downloads.
+ // Replace invalid characters according to the specifications of VFAT.
+ filename = replaceInvalidVfatCharacters(filename);
return filename;
}
@@ -779,4 +780,53 @@ public class Helpers {
resolver.delete(Downloads.Impl.ALL_DOWNLOADS_CONTENT_URI, Downloads.Impl._ID + " = ? ",
new String[]{String.valueOf(id)});
}
+
+ /*
+ * Replace invalid filename characters according to
+ * specifications of the VFAT.
+ * @note Package-private due to testing.
+ */
+ private static String replaceInvalidVfatCharacters(String filename) {
+ final char START_CTRLCODE = 0x00;
+ final char END_CTRLCODE = 0x1f;
+ final char QUOTEDBL = 0x22;
+ final char ASTERISK = 0x2A;
+ final char SLASH = 0x2F;
+ final char COLON = 0x3A;
+ final char LESS = 0x3C;
+ final char GREATER = 0x3E;
+ final char QUESTION = 0x3F;
+ final char BACKSLASH = 0x5C;
+ final char BAR = 0x7C;
+ final char DEL = 0x7F;
+ final char UNDERSCORE = 0x5F;
+
+ StringBuffer sb = new StringBuffer();
+ char ch;
+ boolean isRepetition = false;
+ for (int i = 0; i < filename.length(); i++) {
+ ch = filename.charAt(i);
+ if ((START_CTRLCODE <= ch &&
+ ch <= END_CTRLCODE) ||
+ ch == QUOTEDBL ||
+ ch == ASTERISK ||
+ ch == SLASH ||
+ ch == COLON ||
+ ch == LESS ||
+ ch == GREATER ||
+ ch == QUESTION ||
+ ch == BACKSLASH ||
+ ch == BAR ||
+ ch == DEL){
+ if (!isRepetition) {
+ sb.append(UNDERSCORE);
+ isRepetition = true;
+ }
+ } else {
+ sb.append(ch);
+ isRepetition = false;
+ }
+ }
+ return sb.toString();
+ }
}