diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ScanContent.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ScanContent.java index ab5e8b53c6..445249bb92 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ScanContent.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ScanContent.java @@ -261,7 +261,7 @@ public class ScanContent extends AbstractProcessor { @Override public SearchTerm nextTerm() throws IOException { final String nextLine = reader.readLine(); - if (nextLine == null) { + if (nextLine == null || nextLine.isEmpty()) { return null; } return new SearchTerm<>(nextLine.getBytes("UTF-8")); diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanContent.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanContent.java index 8c368457f4..c221965f64 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanContent.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestScanContent.java @@ -18,6 +18,7 @@ package org.apache.nifi.processors.standard; import java.io.DataOutputStream; import java.io.IOException; +import java.io.StringWriter; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -34,6 +35,24 @@ import org.junit.Test; public class TestScanContent { + @Test + public void testBlankLineInDictionaryTextEncoding() throws IOException { + final String dictionaryWithBlankLine = "Line1\n\nLine3"; + final byte[] dictionaryBytes = dictionaryWithBlankLine.getBytes(ScanContent.UTF8); + final Path dictionaryPath = Paths.get("target/dictionary"); + Files.write(dictionaryPath, dictionaryBytes, StandardOpenOption.CREATE, StandardOpenOption.WRITE); + + final TestRunner runner = TestRunners.newTestRunner(new ScanContent()); + runner.setThreadCount(1); + runner.setProperty(ScanContent.DICTIONARY, dictionaryPath.toString()); + runner.setProperty(ScanContent.DICTIONARY_ENCODING, ScanContent.TEXT_ENCODING); + + runner.enqueue(new byte[0]); + runner.run(); + runner.assertTransferCount(ScanContent.REL_NO_MATCH, 1); + + } + @Ignore("This test has a race condition/ordering problem") @Test public void testBinaryScan() throws IOException {