Skip to content

Commit

Permalink
Sets validator fixes (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea committed Aug 29, 2023
1 parent 04fb6c2 commit 97c61d4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,11 +30,16 @@ public List<String> cleanup(List<String> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ public void duplicatedInputValuesAreRemoved() {

@Test
public void valuesAreSortedAlphanumerically() {
List<String> 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<String> 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
Expand Down Expand Up @@ -75,10 +76,19 @@ public void nullSetIsRemoved() {

@Test
public void setWithExtraWhitespaceIsTrimmed() {
List<String> result = mValidator.cleanup(Arrays.asList("set1 ", " set2", "set3", "set 4"));
List<String> 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<String> 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));
}
}

0 comments on commit 97c61d4

Please sign in to comment.