Not include user input in regex
Check prefix and remove prefix first, to avoid include user input in the regex to fix. Fix: 335136289 Test: manual - on SIMs Test: unit test Change-Id: Iff4dcfc3662c744d00b586d05e64b4f5fe33a0d8
This commit is contained in:
@@ -75,8 +75,9 @@ public class SubscriptionUtil {
|
||||
static final String SUB_ID = "sub_id";
|
||||
@VisibleForTesting
|
||||
static final String KEY_UNIQUE_SUBSCRIPTION_DISPLAYNAME = "unique_subscription_displayName";
|
||||
private static final String REGEX_DISPLAY_NAME_PREFIXES = "^";
|
||||
private static final String REGEX_DISPLAY_NAME_SUFFIXES = "\\s[0-9]+";
|
||||
private static final String REGEX_DISPLAY_NAME_SUFFIX = "\\s[0-9]+";
|
||||
private static final Pattern REGEX_DISPLAY_NAME_SUFFIX_PATTERN =
|
||||
Pattern.compile(REGEX_DISPLAY_NAME_SUFFIX);
|
||||
|
||||
private static List<SubscriptionInfo> sAvailableResultsForTesting;
|
||||
private static List<SubscriptionInfo> sActiveResultsForTesting;
|
||||
@@ -460,12 +461,12 @@ public class SubscriptionUtil {
|
||||
|
||||
@VisibleForTesting
|
||||
static boolean isValidCachedDisplayName(String cachedDisplayName, String originalName) {
|
||||
if (TextUtils.isEmpty(cachedDisplayName) || TextUtils.isEmpty(originalName)) {
|
||||
if (TextUtils.isEmpty(cachedDisplayName) || TextUtils.isEmpty(originalName)
|
||||
|| !cachedDisplayName.startsWith(originalName)) {
|
||||
return false;
|
||||
}
|
||||
String regex = REGEX_DISPLAY_NAME_PREFIXES + originalName + REGEX_DISPLAY_NAME_SUFFIXES;
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(cachedDisplayName);
|
||||
String displayNameSuffix = cachedDisplayName.substring(originalName.length());
|
||||
Matcher matcher = REGEX_DISPLAY_NAME_SUFFIX_PATTERN.matcher(displayNameSuffix);
|
||||
return matcher.matches();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user