From 750e25388fa90c57f2cb648774bd2d908544fcf0 Mon Sep 17 00:00:00 2001 From: rafael81 Date: Wed, 4 Nov 2015 22:18:35 +0900 Subject: [PATCH] Update regular expression pattern for sms verification Closes #4375 --- src/org/thoughtcrime/securesms/service/SmsListener.java | 2 +- .../org/thoughtcrime/securesms/service/SmsListenerTest.java | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/org/thoughtcrime/securesms/service/SmsListener.java b/src/org/thoughtcrime/securesms/service/SmsListener.java index 820dcda33e..1872bb7009 100644 --- a/src/org/thoughtcrime/securesms/service/SmsListener.java +++ b/src/org/thoughtcrime/securesms/service/SmsListener.java @@ -38,7 +38,7 @@ public class SmsListener extends BroadcastReceiver { private static final String SMS_RECEIVED_ACTION = Telephony.Sms.Intents.SMS_RECEIVED_ACTION; private static final String SMS_DELIVERED_ACTION = Telephony.Sms.Intents.SMS_DELIVER_ACTION; - private static final Pattern CHALLENGE_PATTERN = Pattern.compile(".*Your TextSecure verification code: ([0-9]{3,4})-([0-9]{3,4}).*"); + private static final Pattern CHALLENGE_PATTERN = Pattern.compile(".*\\s*Your TextSecure verification code: ([0-9]{3,4})-([0-9]{3,4}).*"); private boolean isExemption(SmsMessage message, String messageBody) { diff --git a/test/androidTest/java/org/thoughtcrime/securesms/service/SmsListenerTest.java b/test/androidTest/java/org/thoughtcrime/securesms/service/SmsListenerTest.java index 85fddd4a46..0e2ad03b6a 100644 --- a/test/androidTest/java/org/thoughtcrime/securesms/service/SmsListenerTest.java +++ b/test/androidTest/java/org/thoughtcrime/securesms/service/SmsListenerTest.java @@ -38,13 +38,14 @@ import static org.mockito.Mockito.when; public class SmsListenerTest extends TextSecureTestCase { private static final String CHALLENGE_SMS_3_3 = "Your TextSecure verification code: 337-337"; + private static final String CHALLENGE_SMS_3_3_PREPEND = "XXX\nYour TextSecure verification code: 1337-1337"; private static final String CHALLENGE_SMS_3_4 = "Your TextSecure verification code: 337-1337"; private static final String CHALLENGE_SMS_4_3 = "Your TextSecure verification code: 1337-337"; private static final String CHALLENGE_SMS_4_4 = "Your TextSecure verification code: 1337-1337"; private static final String CHALLENGE_SMS_4_4_PREPEND = "XXXYour TextSecure verification code: 1337-1337"; private static final String CHALLENGE_SMS_4_4_APPEND = "Your TextSecure verification code: 1337-1337XXX"; private static final String[] CHALLENGE_SMS = { - CHALLENGE_SMS_3_3, CHALLENGE_SMS_3_4, CHALLENGE_SMS_4_3, + CHALLENGE_SMS_3_3, CHALLENGE_SMS_3_3_PREPEND, CHALLENGE_SMS_3_4, CHALLENGE_SMS_4_3, CHALLENGE_SMS_4_4, CHALLENGE_SMS_4_4_PREPEND, CHALLENGE_SMS_4_4_APPEND }; @@ -53,7 +54,7 @@ public class SmsListenerTest extends TextSecureTestCase { private static final String CHALLENGE_4_3 = "1337337"; private static final String CHALLENGE_4_4 = "13371337"; private static final String[] CHALLENGES = { - CHALLENGE_3_3, CHALLENGE_3_4, CHALLENGE_4_3, + CHALLENGE_3_3, CHALLENGE_3_3, CHALLENGE_3_4, CHALLENGE_4_3, CHALLENGE_4_4, CHALLENGE_4_4, CHALLENGE_4_4, };