summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJin Cao <jinyan@google.com>2014-03-26 16:49:48 -0700
committerJin Cao <jinyan@google.com>2014-03-27 13:23:13 -0700
commitd67d7e392e895bf7ea0452d020f57bd04c43fd63 (patch)
treeecac3f3adb045bbc8e7531f1f001ba5af133ad5b /src
parent5506369d57ffff90cbda613c561f5c03df6a4fd1 (diff)
downloadandroid_packages_apps_UnifiedEmail-d67d7e392e895bf7ea0452d020f57bd04c43fd63.tar.gz
android_packages_apps_UnifiedEmail-d67d7e392e895bf7ea0452d020f57bd04c43fd63.tar.bz2
android_packages_apps_UnifiedEmail-d67d7e392e895bf7ea0452d020f57bd04c43fd63.zip
Fixed bug with % encoding
The app crashes when %25 exists in the body of mailto (actually also crashes if it's in the subject). This is caused by attempting to decode % encoding twice through getQueryParameters and URLDecoder.decode. e.g. body=Bye%25Bye, after getQueryParameters. the string turns into Bye%Bye, then passing that into URLDecoder.decode will throw error because %Bye is not a valid % encoding. To fix, we manually re-encode %, then run it through URLDecoder to get the correct message. Added unit tests to test full functionality of initFromMailTo with various inputs to make sure that they are displayed correctly. Tested original bug on phone, and % sign is rendered correctly with no crashes. b/12441256 Change-Id: I06b2a4378f11de58d59b4978db1af751928570c7
Diffstat (limited to 'src')
-rw-r--r--src/com/android/mail/compose/ComposeActivity.java41
1 files changed, 28 insertions, 13 deletions
diff --git a/src/com/android/mail/compose/ComposeActivity.java b/src/com/android/mail/compose/ComposeActivity.java
index c0768edb3..3a285a556 100644
--- a/src/com/android/mail/compose/ComposeActivity.java
+++ b/src/com/android/mail/compose/ComposeActivity.java
@@ -1465,6 +1465,31 @@ public class ComposeActivity extends Activity implements OnClickListener, OnNavi
}
/**
+ * Replaces all occurrences of '%' with "%25", to prevent URLDecode.decode from
+ * crashing on decoded '%' symbols
+ *
+ * @param toReplace Input string
+ * @return The string with all "%" characters replaced with "%25"
+ */
+ private static String replacePercent(String toReplace) {
+ return toReplace.replace("%", "%25");
+ }
+
+ /**
+ * Helper function to encapsulate encoding/decoding string from Uri.getQueryParameters
+ * @param content Input string
+ * @return The string that's properly escaped to be shown in mail subject/content
+ */
+ private static String decodeContentFromQueryParam(String content) {
+ try {
+ return URLDecoder.decode(replacePlus(replacePercent(content)), UTF8_ENCODING_NAME);
+ } catch (UnsupportedEncodingException e) {
+ LogUtils.e(LOG_TAG, "%s while decoding '%s'", e.getMessage(), content);
+ return ""; // Default to empty string so setText/setBody has same behavior as before.
+ }
+ }
+
+ /**
* Initialize the compose view from a String representing a mailTo uri.
* @param mailToString The uri as a string.
*/
@@ -1502,25 +1527,15 @@ public class ComposeActivity extends Activity implements OnClickListener, OnNavi
List<String> bcc = uri.getQueryParameters("bcc");
addBccAddresses(Arrays.asList(bcc.toArray(new String[bcc.size()])));
+ // NOTE: Uri.getQueryParameters already decodes % encoded characters
List<String> subject = uri.getQueryParameters("subject");
if (subject.size() > 0) {
- try {
- mSubject.setText(URLDecoder.decode(replacePlus(subject.get(0)),
- UTF8_ENCODING_NAME));
- } catch (UnsupportedEncodingException e) {
- LogUtils.e(LOG_TAG, "%s while decoding subject '%s'",
- e.getMessage(), subject);
- }
+ mSubject.setText(decodeContentFromQueryParam(subject.get(0)));
}
List<String> body = uri.getQueryParameters("body");
if (body.size() > 0) {
- try {
- setBody(URLDecoder.decode(replacePlus(body.get(0)), UTF8_ENCODING_NAME),
- true /* with signature */);
- } catch (UnsupportedEncodingException e) {
- LogUtils.e(LOG_TAG, "%s while decoding body '%s'", e.getMessage(), body);
- }
+ setBody(decodeContentFromQueryParam(body.get(0)), true /* with signature */);
}
}