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

fix(nm): Fix dns list wrongly split. #4576

Merged
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 @@ -101,7 +101,8 @@ public List<String> getStringList(String key, Object... args) {
List<String> stringList = new ArrayList<>();
Pattern comma = Pattern.compile(",");
if (Objects.nonNull(commaSeparatedString) && !commaSeparatedString.isEmpty()) {
comma.splitAsStream(commaSeparatedString).filter(s -> !s.trim().isEmpty()).forEach(stringList::add);
comma.splitAsStream(commaSeparatedString).filter(s -> !s.trim().isEmpty()).map(String::trim)
.forEach(stringList::add);
}

return stringList;
Expand All @@ -115,7 +116,8 @@ public Optional<List<String>> getOptStringList(String key, Object... args) {

List<String> stringList = new ArrayList<>();
Pattern comma = Pattern.compile(",");
comma.splitAsStream(commaSeparatedString.get()).filter(s -> !s.trim().isEmpty()).forEach(stringList::add);
comma.splitAsStream(commaSeparatedString.get()).filter(s -> !s.trim().isEmpty()).map(String::trim)
.forEach(stringList::add);

return Optional.of(stringList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,22 +259,22 @@ public void getOptShouldWorkWithDecryptedEmptyPassword() {
public void getStringListShouldWorkWithSimpleMap() {
givenMapWith("testKeyNull", null);
givenMapWith("testKey1", "testString1");
givenMapWith("testKey-comma-seperated", "commaSeperated1,commaSeperated2,commaSeperated3");
givenMapWith("testKey-comma-seperated", "commaSeparated1,commaSeparated2,commaSeparated3");
givenNetworkPropertiesBuiltWith(this.properties);
whenGetStringListIsCalledWith("testKey-comma-seperated");
thenNoExceptionsOccured();
thenStringListResultEquals(Arrays.asList("commaSeperated1", "commaSeperated2", "commaSeperated3"));
thenStringListResultEquals(Arrays.asList("commaSeparated1", "commaSeparated2", "commaSeparated3"));
}

@Test
public void getStringListShouldWorkWithMultipleCommas() {
givenMapWith("testKeyNull", null);
givenMapWith("testKey1", "testString1");
givenMapWith("testKey-comma-seperated", ",, ,,,commaSeperated1, ,,,,commaSeperated2, ,,commaSeperated3,");
givenMapWith("testKey-comma-seperated", ",, ,,,commaSeparated1, ,,,,commaSeparated2, ,,commaSeparated3,");
givenNetworkPropertiesBuiltWith(this.properties);
whenGetStringListIsCalledWith("testKey-comma-seperated");
thenNoExceptionsOccured();
thenStringListResultEquals(Arrays.asList("commaSeperated1", "commaSeperated2", "commaSeperated3"));
thenStringListResultEquals(Arrays.asList("commaSeparated1", "commaSeparated2", "commaSeparated3"));
}

@Test
Expand Down Expand Up @@ -304,21 +304,30 @@ public void getStringListShouldWorkWithNoCommas() {

@Test
public void getOptStringListShouldWorkWithSimpleMap() {
givenMapWith("testKey-comma-seperated", "commaSeperated1,commaSeperated2,commaSeperated3");
givenMapWith("testKey-comma-seperated", "commaSeparated1,commaSeparated2,commaSeparated3");
givenNetworkPropertiesBuiltWith(this.properties);
whenGetOptStringListIsCalledWith("testKey-comma-seperated");
thenNoExceptionsOccured();
thenOptionalResultEquals(Optional.of(Arrays.asList("commaSeperated1", "commaSeperated2", "commaSeperated3")));
thenOptionalResultEquals(Optional.of(Arrays.asList("commaSeparated1", "commaSeparated2", "commaSeparated3")));
}

@Test
public void getOptStringListWithSpacesShouldWorkWithSimpleMap() {
givenMapWith("testKey-comma-seperated", "commaSeparated1 ,commaSeparated2 ,commaSeparated3");
givenNetworkPropertiesBuiltWith(this.properties);
whenGetOptStringListIsCalledWith("testKey-comma-seperated");
thenNoExceptionsOccured();
thenOptionalResultEquals(Optional.of(Arrays.asList("commaSeparated1", "commaSeparated2", "commaSeparated3")));
}

@Test
public void getOptStringListShouldWorkWithMalformed() {
givenMapWith("testKey-comma-seperated",
", , ,,,,commaSeperated1, , , ,,,,,commaSeperated2,,,, ,, ,,commaSeperated3,, , ,,,, ,");
", , ,,,,commaSeparated1, , , ,,,,,commaSeparated2,,,, ,, ,,commaSeparated3,, , ,,,, ,");
givenNetworkPropertiesBuiltWith(this.properties);
whenGetOptStringListIsCalledWith("testKey-comma-seperated");
thenNoExceptionsOccured();
thenOptionalResultEquals(Optional.of(Arrays.asList("commaSeperated1", "commaSeperated2", "commaSeperated3")));
thenOptionalResultEquals(Optional.of(Arrays.asList("commaSeparated1", "commaSeparated2", "commaSeparated3")));
}

@Test
Expand Down