mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-10 13:21:53 +01:00
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:
parent
1145613cba
commit
5cf91cde1b
@ -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) {
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user