diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index 0bc5b8475e..8e8d306867 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -716,6 +716,9 @@ pub fn (s string) count(substr string) int { } pub fn (s string) contains(p string) bool { + if p.len == 0 { + return true + } s.index(p) or { return false } diff --git a/vlib/builtin/string_test.v b/vlib/builtin/string_test.v index e7a66e5fc2..bb7f0c8e96 100644 --- a/vlib/builtin/string_test.v +++ b/vlib/builtin/string_test.v @@ -357,6 +357,8 @@ fn test_contains() { s := 'view.v' assert s.contains('vi') assert !s.contains('random') + assert ''.contains('') + assert 'abc'.contains('') } fn test_arr_contains() {