Filter out blank lines and comments in a multi-line transformations (#4357)

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
This commit is contained in:
jimtng 2024-09-07 14:59:22 +10:00 committed by GitHub
parent 1145613cba
commit 5cf91cde1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

View File

@ -56,8 +56,13 @@ public class ChannelTransformation {
public ChannelTransformation(@Nullable List<String> transformationStrings) {
if (transformationStrings != null) {
try {
transformationSteps = transformationStrings.stream()
.flatMap(ChannelTransformation::splitTransformationString).map(TransformationStep::new)
transformationSteps = transformationStrings.stream() //
.map(String::trim) //
.filter(line -> !line.isBlank()) //
.filter(line -> !line.startsWith("#")) //
.filter(line -> !line.startsWith("//")) //
.flatMap(ChannelTransformation::splitTransformationString) //
.map(TransformationStep::new) //
.toList();
return;
} catch (IllegalArgumentException e) {

View File

@ -349,4 +349,15 @@ public class ChannelTransformationTest {
assertFalse(ChannelTransformation.isValidTransformation("FOO∩BAZ:BAR"));
assertFalse(ChannelTransformation.isValidTransformation("FOO∩BAZ(BAR)"));
}
@Test
public void testBlanksAndCommentsAreDiscarded() {
List<String> pattern = List.of("#hash comment", "//double slashes", " # preceded by spaces",
" // ditto for slashes", " ", "\t", "\t\t\t", "\t# preceded by a tab",
"\t // preceded by tab and space");
ChannelTransformation transformation = new ChannelTransformation(pattern);
assertTrue(transformation.isEmpty());
}
}