diff --git a/src/main/java/io/split/android/client/validators/FlagSetsValidatorImpl.java b/src/main/java/io/split/android/client/validators/FlagSetsValidatorImpl.java index 5553eaa37..57642a6ec 100644 --- a/src/main/java/io/split/android/client/validators/FlagSetsValidatorImpl.java +++ b/src/main/java/io/split/android/client/validators/FlagSetsValidatorImpl.java @@ -66,7 +66,7 @@ public boolean isValid(String value) { } @Override - public Set items(List values, FlagSetsFilter flagSetsFilter) { + public Set items(String method, List values, FlagSetsFilter flagSetsFilter) { Set setsToReturn = new HashSet<>(); if (values == null || values.isEmpty()) { @@ -74,11 +74,23 @@ public Set items(List values, FlagSetsFilter flagSetsFilter) { } for (String flagSet : values) { + if (flagSet.trim().length() != flagSet.length()) { + Logger.w(method + ": Flag Set name " + flagSet + " has extra whitespace, trimming"); + flagSet = flagSet.trim(); + } + + if (!flagSet.toLowerCase().equals(flagSet)) { + Logger.w(method + ": Flag Set name "+flagSet+" should be all lowercase - converting string to lowercase"); + flagSet = flagSet.toLowerCase(); + } + if (!isValid(flagSet)) { + Logger.w(method + ": you passed "+ flagSet +", Flag Set must adhere to the regular expressions "+ FLAG_SET_REGEX +". This means a Flag Set must be start with a letter, be in lowercase, alphanumeric and have a max length of 50 characters. "+ flagSet +" was discarded."); continue; } if (flagSetsFilter != null && !flagSetsFilter.intersect(flagSet)) { + Logger.w(method + ": you passed Flag Set: "+ flagSet +" and is not part of the configured Flag set list, ignoring the request."); continue; } diff --git a/src/main/java/io/split/android/client/validators/SplitFilterValidator.java b/src/main/java/io/split/android/client/validators/SplitFilterValidator.java index b5f0d1b2b..1e3255b84 100644 --- a/src/main/java/io/split/android/client/validators/SplitFilterValidator.java +++ b/src/main/java/io/split/android/client/validators/SplitFilterValidator.java @@ -11,7 +11,7 @@ public interface SplitFilterValidator { boolean isValid(String value); - Set items(List values, FlagSetsFilter flagSetsFilter); + Set items(String method, List values, FlagSetsFilter flagSetsFilter); class ValidationResult { diff --git a/src/main/java/io/split/android/client/validators/TreatmentManagerImpl.java b/src/main/java/io/split/android/client/validators/TreatmentManagerImpl.java index 23276e026..05469a2bf 100644 --- a/src/main/java/io/split/android/client/validators/TreatmentManagerImpl.java +++ b/src/main/java/io/split/android/client/validators/TreatmentManagerImpl.java @@ -191,7 +191,7 @@ public Map getTreatmentsByFlagSet(@NonNull String flagSet, @Null mValidationLogger.e(CLIENT_DESTROYED_MESSAGE, validationTag); return controlTreatmentsForSplits(new ArrayList<>(names), validationTag); } - names = getNamesFromSet(Collections.singletonList(flagSet)); + names = getNamesFromSet("getTreatmentsByFlagSet", Collections.singletonList(flagSet)); long start = System.currentTimeMillis(); try { @@ -216,7 +216,7 @@ public Map getTreatmentsByFlagSets(@NonNull List flagSet mValidationLogger.e(CLIENT_DESTROYED_MESSAGE, validationTag); return controlTreatmentsForSplits(new ArrayList<>(names), validationTag); } - names = getNamesFromSet(flagSets); + names = getNamesFromSet("getTreatmentsByFlagSets", flagSets); long start = System.currentTimeMillis(); try { @@ -237,7 +237,7 @@ public Map getTreatmentsWithConfigByFlagSet(@NonNull String String validationTag = ValidationTag.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET; Set names = new HashSet<>(); try { - names = getNamesFromSet(Collections.singletonList(flagSet)); + names = getNamesFromSet("getTreatmentsWithConfigByFlagSet", Collections.singletonList(flagSet)); if (isClientDestroyed) { mValidationLogger.e(CLIENT_DESTROYED_MESSAGE, validationTag); return controlTreatmentsForSplitsWithConfig(new ArrayList<>(names), validationTag); @@ -266,7 +266,7 @@ public Map getTreatmentsWithConfigByFlagSets(@NonNull List< mValidationLogger.e(CLIENT_DESTROYED_MESSAGE, validationTag); return controlTreatmentsForSplitsWithConfig(new ArrayList<>(names), validationTag); } - names = getNamesFromSet(flagSets); + names = getNamesFromSet("getTreatmentsWithConfigByFlagSets", flagSets); long start = System.currentTimeMillis(); try { @@ -403,9 +403,9 @@ private void recordLatency(Method treatment, long startTime) { } @NonNull - private Set getNamesFromSet(@NonNull List flagSets) { + private Set getNamesFromSet(@NonNull String method, @NonNull List flagSets) { - Set setsToEvaluate = mFlagSetsValidator.items(flagSets, mFlagSetsFilter); + Set setsToEvaluate = mFlagSetsValidator.items(method, flagSets, mFlagSetsFilter); if (setsToEvaluate.isEmpty()) { return new HashSet<>();