diff --git a/src/main/java/emissary/util/search/KeywordScanner.java b/src/main/java/emissary/util/search/KeywordScanner.java index 32f0a7d416..d6977b4817 100755 --- a/src/main/java/emissary/util/search/KeywordScanner.java +++ b/src/main/java/emissary/util/search/KeywordScanner.java @@ -159,7 +159,7 @@ public List listIndexOf(@Nullable final byte[] patternArg, final int st if ((start >= this.dataLength) || (stop > this.dataLength) || (patternArg == null)) { return List.of(); } - int newStart = 0; + int newStart = start; int actualStart; int position = 0; this.pattern = patternArg; diff --git a/src/test/java/emissary/util/search/ByteMatcherTest.java b/src/test/java/emissary/util/search/ByteMatcherTest.java index 9aa26959f4..ae8ad8dc36 100644 --- a/src/test/java/emissary/util/search/ByteMatcherTest.java +++ b/src/test/java/emissary/util/search/ByteMatcherTest.java @@ -116,6 +116,12 @@ void testListIndexOf() { assertEquals(findTestCaseInsensitive, this.bl.indexListIgnoreCase("test", 0)); assertEquals(findTestCaseInsensitive, this.bl.indexListIgnoreCase("test", 0, LIST_DATA.length())); + // Test startOffset and endOffset + List testStartOffs = List.of(26, 47, 53); + List testEndOffs = List.of(26, 47); + assertEquals(testStartOffs, this.bl.indexListIgnoreCase("test".getBytes(), 15, LIST_DATA.length())); + assertEquals(testEndOffs, this.bl.listIndexOf("test".getBytes(), 15, 52)); + } @Test diff --git a/src/test/java/emissary/util/search/KeywordScannerTest.java b/src/test/java/emissary/util/search/KeywordScannerTest.java index 39911c3f5e..625385ec20 100644 --- a/src/test/java/emissary/util/search/KeywordScannerTest.java +++ b/src/test/java/emissary/util/search/KeywordScannerTest.java @@ -111,6 +111,12 @@ void testListIndexOf() { assertEquals(findIs, lks.listIndexOf("is".getBytes(), 0)); assertEquals(findIs, lks.listIndexOf("is".getBytes(), 0, LIST_DATA.length)); + List startOffset = List.of(21, 39, 42); + assertEquals(startOffset, lks.listIndexOf("is".getBytes(), 6)); + assertEquals(startOffset, lks.listIndexOf("is".getBytes(), 6, LIST_DATA.length)); + + List endOffset = List.of(2, 5, 21); + assertEquals(endOffset, lks.listIndexOf("is".getBytes(), 0, 38)); } @Test