fix: handle empty search string in string_contains by checking search length only
Previously, the corner case for empty strings only returned true when both the source and search strings were empty. This fix changes the condition to return true whenever the search string is empty, as the empty string is always contained within any string.
This commit is contained in:
+2
-2
@@ -1156,8 +1156,8 @@ DEF_NATIVE(string_contains)
|
|||||||
ObjString* string = AS_STRING(args[0]);
|
ObjString* string = AS_STRING(args[0]);
|
||||||
ObjString* search = AS_STRING(args[1]);
|
ObjString* search = AS_STRING(args[1]);
|
||||||
|
|
||||||
// Corner case, the empty string contains the empty string.
|
// Corner case, the empty string is always contained.
|
||||||
if (string->length == 0 && search->length == 0) RETURN_TRUE;
|
if (search->length == 0) RETURN_TRUE;
|
||||||
|
|
||||||
RETURN_BOOL(wrenStringFind(vm, string, search) != string->length);
|
RETURN_BOOL(wrenStringFind(vm, string, search) != string->length);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user