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 550342bc3..72daeb055 100644 --- a/src/main/java/io/split/android/client/validators/FlagSetsValidatorImpl.java +++ b/src/main/java/io/split/android/client/validators/FlagSetsValidatorImpl.java @@ -9,7 +9,7 @@ public class FlagSetsValidatorImpl implements SplitFilterValidator { - private static final String FLAG_SET_REGEX = "^[a-z][_a-z0-9]{0,49}$"; + private static final String FLAG_SET_REGEX = "^[a-z0-9][_a-z0-9]{0,49}$"; /** * Validates the flag sets and returns a list of @@ -30,11 +30,16 @@ public List cleanup(List values) { continue; } - if (set.startsWith(" ") || set.endsWith(" ")) { + if (set.trim().length() != set.length()) { Logger.w("SDK config: Flag Set name " + set + " has extra whitespace, trimming"); set = set.trim(); } + if (!set.toLowerCase().equals(set)) { + Logger.w("SDK config: Flag Set name "+set+" should be all lowercase - converting string to lowercase"); + set = set.toLowerCase(); + } + if (set.matches(FLAG_SET_REGEX)) { cleanedUpSets.add(set); } else { diff --git a/src/test/java/io/split/android/client/validators/FlagSetsValidatorImplTest.java b/src/test/java/io/split/android/client/validators/FlagSetsValidatorImplTest.java index 5dce643d1..cd8bc9604 100644 --- a/src/test/java/io/split/android/client/validators/FlagSetsValidatorImplTest.java +++ b/src/test/java/io/split/android/client/validators/FlagSetsValidatorImplTest.java @@ -34,11 +34,12 @@ public void duplicatedInputValuesAreRemoved() { @Test public void valuesAreSortedAlphanumerically() { - List result = mValidator.cleanup(Arrays.asList("set2", "set1", "set_1")); - assertEquals(3, result.size()); - assertEquals("set1", result.get(0)); - assertEquals("set2", result.get(1)); - assertEquals("set_1", result.get(2)); + List result = mValidator.cleanup(Arrays.asList("set2", "set1", "set_1", "1set")); + assertEquals(4, result.size()); + assertEquals("1set", result.get(0)); + assertEquals("set1", result.get(1)); + assertEquals("set2", result.get(2)); + assertEquals("set_1", result.get(3)); } @Test @@ -75,10 +76,19 @@ public void nullSetIsRemoved() { @Test public void setWithExtraWhitespaceIsTrimmed() { - List result = mValidator.cleanup(Arrays.asList("set1 ", " set2", "set3", "set 4")); + List result = mValidator.cleanup(Arrays.asList("set1 ", " set2\r", "set3 ", "set 4\n")); assertEquals(3, result.size()); assertEquals("set1", result.get(0)); assertEquals("set2", result.get(1)); assertEquals("set3", result.get(2)); } + + @Test + public void setsAreLowercase() { + List result = mValidator.cleanup(Arrays.asList("SET1", "Set2", "SET_3")); + assertEquals(3, result.size()); + assertEquals("set1", result.get(0)); + assertEquals("set2", result.get(1)); + assertEquals("set_3", result.get(2)); + } }