Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR Fixes #527

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}