Skip to content

Commit 15a94b0

Browse files
committed
#4204 Make indexOf() and lastIndexOf() return -1 when not found
1 parent 1a704fe commit 15a94b0

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

stroom-query/stroom-query-language/src/main/java/stroom/query/language/functions/Substring.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,7 @@ public Val eval(final StoredValues storedValues, final Supplier<ChildData> child
188188
int start = startPos;
189189
int end = endPos;
190190

191-
if (start < 0) {
192-
start = 0;
193-
}
194-
195-
if (end < 0 || end < start || start >= value.length()) {
191+
if (start < 0 || end < start || start >= value.length()) {
196192
return ValString.EMPTY;
197193
}
198194

stroom-query/stroom-query-language/src/test/java/stroom/query/language/functions/TestExpressionParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ void testIndexOf3() {
499499
void testIndexOf4() {
500500
compute("substring(${val1}, indexOf(${val1}, 'q'), stringLength(${val1}))",
501501
Val.of("aa-bb"),
502-
out -> assertThat(out.type().isError()).isTrue());
502+
out -> assertThat(out.toString()).isEqualTo(""));
503503
}
504504

505505
@Test
@@ -527,7 +527,7 @@ void testLastIndexOf3() {
527527
void testLastIndexOf4() {
528528
compute("substring(${val1}, lastIndexOf(${val1}, 'q'), stringLength(${val1}))",
529529
Val.of("aa-bb"),
530-
out -> assertThat(out.type().isError()).isTrue());
530+
out -> assertThat(out.toString()).isEqualTo(""));
531531
}
532532

533533
@Test

0 commit comments

Comments
 (0)