Merge pull request #2320 from mushroom-dev/mushroom/trim_sms

Trim leading and trailing whitespaces in incoming SMS messages
This commit is contained in:
Milos Kozak 2023-01-03 12:24:32 +01:00 committed by GitHub
commit 757544e2b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -259,7 +259,7 @@ class SmsCommunicatorPlugin @Inject constructor(
val pump = activePlugin.activePump
messages.add(receivedSms)
aapsLogger.debug(LTag.SMS, receivedSms.toString())
val divided = receivedSms.text.split(Regex("\\s+")).toTypedArray()
val divided = receivedSms.text.trim().split(Regex("\\s+")).toTypedArray()
val remoteCommandsAllowed = sp.getBoolean(R.string.key_smscommunicator_remote_commands_allowed, false)
val minDistance =
@ -1226,6 +1226,7 @@ class SmsCommunicatorPlugin @Inject constructor(
override fun sendSMS(sms: Sms): Boolean {
sms.text = stripAccents(sms.text)
try {
aapsLogger.debug(LTag.SMS, "Sending SMS to " + sms.phoneNumber + ": " + sms.text)
if (sms.text.toByteArray().size <= 140) smsManager?.sendTextMessage(sms.phoneNumber, null, sms.text, null, null)