Skip to content

Commit 8a0a316

Browse files
ruanwenjunanthonycorbacho
authored andcommitted
fix can match empty line (thekrakken#109)
1 parent 5198ad7 commit 8a0a316

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/main/java/io/krakens/grok/api/Grok.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public ArrayList<Map<String, Object>> capture(List<String> logs) {
162162
* @return Grok Match
163163
*/
164164
public Match match(CharSequence text) {
165-
if (compiledNamedRegex == null || StringUtils.isBlank(text)) {
165+
if (compiledNamedRegex == null || text == null) {
166166
return Match.EMPTY;
167167
}
168168

src/test/java/io/krakens/grok/api/GrokTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,4 +671,17 @@ public void testTimeZone() {
671671
instant = (Instant) grok.match(dateWithTimeZone).capture().get("timestamp");
672672
assertEquals(ZonedDateTime.parse(dateWithTimeZone, dtf.withZone(ZoneOffset.ofHours(8))).toInstant(), instant);
673673
}
674+
675+
@Test
676+
public void testEmptyLine() {
677+
GrokCompiler grokCompiler = GrokCompiler.newInstance();
678+
grokCompiler.registerDefaultPatterns();
679+
final Grok grok = grokCompiler.compile("%{GREEDYDATA}");
680+
681+
// empty line
682+
String line = " ";
683+
Match gm = grok.match(line);
684+
Map<String, Object> capture = gm.capture();
685+
assertEquals(1, capture.size());
686+
}
674687
}

0 commit comments

Comments
 (0)