mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 17:27:45 +00:00
fix receiving utf-8 characters in multimedia push messages
Throw AssertionError instead of logging and trying to recover
This commit is contained in:
parent
7a3d509ef4
commit
03ecd79fe0
@ -9,6 +9,7 @@ import org.whispersystems.textsecure.push.PushMessageProtos.PushMessageContent;
|
|||||||
import org.whispersystems.textsecure.util.Base64;
|
import org.whispersystems.textsecure.util.Base64;
|
||||||
import org.whispersystems.textsecure.util.Hex;
|
import org.whispersystems.textsecure.util.Hex;
|
||||||
|
|
||||||
|
import ws.com.google.android.mms.pdu.CharacterSets;
|
||||||
import ws.com.google.android.mms.pdu.EncodedStringValue;
|
import ws.com.google.android.mms.pdu.EncodedStringValue;
|
||||||
import ws.com.google.android.mms.pdu.PduBody;
|
import ws.com.google.android.mms.pdu.PduBody;
|
||||||
import ws.com.google.android.mms.pdu.PduHeaders;
|
import ws.com.google.android.mms.pdu.PduHeaders;
|
||||||
@ -50,8 +51,9 @@ public class IncomingMediaMessage {
|
|||||||
|
|
||||||
if (!org.whispersystems.textsecure.util.Util.isEmpty(messageContent.getBody())) {
|
if (!org.whispersystems.textsecure.util.Util.isEmpty(messageContent.getBody())) {
|
||||||
PduPart text = new PduPart();
|
PduPart text = new PduPart();
|
||||||
text.setData(Util.toIsoBytes(messageContent.getBody()));
|
text.setData(Util.toUtf8Bytes(messageContent.getBody()));
|
||||||
text.setContentType(Util.toIsoBytes("text/plain"));
|
text.setContentType(Util.toIsoBytes("text/plain"));
|
||||||
|
text.setCharset(CharacterSets.UTF_8);
|
||||||
body.addPart(text);
|
body.addPart(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,9 +98,7 @@ public class Util {
|
|||||||
try {
|
try {
|
||||||
return new String(bytes, CharacterSets.MIMENAME_ISO_8859_1);
|
return new String(bytes, CharacterSets.MIMENAME_ISO_8859_1);
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
// Impossible to reach here!
|
throw new AssertionError("ISO_8859_1 must be supported!");
|
||||||
Log.e("MmsDatabase", "ISO_8859_1 must be supported!", e);
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,8 +106,15 @@ public class Util {
|
|||||||
try {
|
try {
|
||||||
return isoString.getBytes(CharacterSets.MIMENAME_ISO_8859_1);
|
return isoString.getBytes(CharacterSets.MIMENAME_ISO_8859_1);
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
Log.w("Util", "ISO_8859_1 must be supported!", e);
|
throw new AssertionError("ISO_8859_1 must be supported!");
|
||||||
return new byte[0];
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] toUtf8Bytes(String utf8String) {
|
||||||
|
try {
|
||||||
|
return utf8String.getBytes(CharacterSets.MIMENAME_UTF_8);
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
throw new AssertionError("UTF_8 must be supported!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user