Skip to content

Commit

Permalink
fixing starting offset of listIndexOf method in KeywordScanner (#1007)
Browse files Browse the repository at this point in the history
  • Loading branch information
nixon124 authored Nov 7, 2024
1 parent 97fe2d7 commit bb507fa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/emissary/util/search/KeywordScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public List<Integer> 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;
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/emissary/util/search/ByteMatcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> testStartOffs = List.of(26, 47, 53);
List<Integer> 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
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/emissary/util/search/KeywordScannerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ void testListIndexOf() {
assertEquals(findIs, lks.listIndexOf("is".getBytes(), 0));
assertEquals(findIs, lks.listIndexOf("is".getBytes(), 0, LIST_DATA.length));

List<Integer> startOffset = List.of(21, 39, 42);
assertEquals(startOffset, lks.listIndexOf("is".getBytes(), 6));
assertEquals(startOffset, lks.listIndexOf("is".getBytes(), 6, LIST_DATA.length));

List<Integer> endOffset = List.of(2, 5, 21);
assertEquals(endOffset, lks.listIndexOf("is".getBytes(), 0, 38));
}

@Test
Expand Down

0 comments on commit bb507fa

Please sign in to comment.