Skip to content

Commit

Permalink
Fix parsing empty value with brackets failed in Dissect ingest proces…
Browse files Browse the repository at this point in the history
…sor (#65524) (#67827)
  • Loading branch information
danhermann committed Jan 21, 2021
1 parent d46dd3b commit 8305645
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public Map<String, String> parse(String inputString) {
int lookAheadMatches;
//start walking the input string byte by byte, look ahead for matches where needed
//if a match is found jump forward to the end of the match
for (; i < input.length; i++) {
while (i < input.length) {
lookAheadMatches = 0;
//potential match between delimiter and input string
if (delimiter.length > 0 && input[i] == delimiter[0]) {
Expand Down Expand Up @@ -263,7 +263,11 @@ public Map<String, String> parse(String inputString) {
delimiter = dissectPair.getDelimiter().getBytes(StandardCharsets.UTF_8);
//i is always one byte after the last found delimiter, aka the start of the next value
valueStart = i;
} else {
i++;
}
} else {
i++;
}
}
//the last key, grab the rest of the input (unless consecutive delimiters already grabbed the last key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ public void testLeadingDelimiter() {
assertMatch(",%{a} %{b}", ",,foo bar", Arrays.asList("a", "b"), Arrays.asList(",foo", "bar"));
}

public void testEmptyValueWithBrackets() {
assertMatch("(%{a}) [%{b}] -[%{c}]", "(foo) [] -[bar]", Arrays.asList("a", "b", "c"), Arrays.asList("foo", "", "bar"));
assertMatch("[%{a}] [%{b}]", "[] []", Arrays.asList("a", "b"), Arrays.asList("", ""));
}

/**
* Runtime errors
*/
Expand Down

0 comments on commit 8305645

Please sign in to comment.