Skip to content

Commit fc673d0

Browse files
committed
Potential fix
1 parent 21780e6 commit fc673d0

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

libs/dissect/src/main/java/org/elasticsearch/dissect/DissectParser.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public Map<String, String> parse(String inputString) {
227227
// jump to the end of the match
228228
i += lookAheadMatches;
229229
// look for consecutive delimiters (e.g. a,,,,d,e)
230-
while (i < input.length) {
230+
while (dissectPair.key.skipRightPadding() && i < input.length) {
231231
lookAheadMatches = 0;
232232
for (int j = 0; j < delimiter.length; j++) {
233233
if (i + j < input.length && input[i + j] == delimiter[j]) {
@@ -238,16 +238,6 @@ public Map<String, String> parse(String inputString) {
238238
if (lookAheadMatches == delimiter.length) {
239239
// jump to the end of the match
240240
i += lookAheadMatches;
241-
if (key.skipRightPadding() == false) {
242-
// progress the keys/delimiter if possible
243-
if (it.hasNext() == false) {
244-
break; // the while loop
245-
}
246-
dissectPair = it.next();
247-
key = dissectPair.key();
248-
// add the key with an empty value for the empty delimiter
249-
dissectMatch.add(key, "");
250-
}
251241
} else {
252242
break; // the while loop
253243
}

libs/dissect/src/test/java/org/elasticsearch/dissect/DissectParserTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public void testConsecutiveDelimiters() {
316316
}
317317

318318
public void testAppendWithConsecutiveDelimiters() {
319-
assertMatch("%{+a/1},%{+a/3}-%{+a/2} %{b}", "foo,bar----baz lol", Arrays.asList("a", "b"), Arrays.asList("foobar", ""));
319+
assertMatch("%{+a/1},%{+a/3}-%{+a/2} %{b}", "foo,bar----baz lol", Arrays.asList("a", "b"), Arrays.asList("foo---bazbar", "lol"));
320320
assertMatch("%{+a/1},%{+a/3->}-%{+a/2} %{b}", "foo,bar----baz lol", Arrays.asList("a", "b"), Arrays.asList("foobazbar", "lol"));
321321
}
322322

@@ -476,6 +476,12 @@ public void testReferenceKeys() {
476476
assertThat(new DissectParser("%{a} %{b} %{*c} %{&c} %{*d} %{&d}", "").referenceKeys(), contains("c", "d"));
477477
}
478478

479+
// Test for elasticsearch#119264
480+
public void testConcurrentDelimitersAdditional() {
481+
assertMatch("%{a}-%{b}", "foo------bar", Arrays.asList("a", "b"), Arrays.asList("foo", "-----bar"));
482+
assertMatch("%{}|%{}|foo=%{field}", "||foo=bar", Arrays.asList("field"), Arrays.asList("bar"));
483+
}
484+
479485
private DissectException assertFail(String pattern, String input) {
480486
return expectThrows(DissectException.class, () -> new DissectParser(pattern, null).forceParse(input));
481487
}

0 commit comments

Comments
 (0)