Skip to content

Commit 0504998

Browse files
authored
Fix std.member matching sub strings (#657)
* Fix std.member for strings * Add test case for matching substr in std.member
1 parent b4633b6 commit 0504998

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

builtins.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -573,12 +573,13 @@ func rawMember(i *interpreter, arrv, value value) (bool, error) {
573573
if err != nil {
574574
return false, err
575575
}
576-
for _, char := range arrType.getRunes() {
577-
if string(char) == valString.getGoString() {
578-
return true, nil
579-
}
576+
577+
arrString, err := i.getString(arrv)
578+
if err != nil {
579+
return false, err
580580
}
581-
return false, nil
581+
582+
return strings.Contains(arrString.getGoString(), valString.getGoString()), nil
582583
case *valueArray:
583584
for _, elem := range arrType.elements {
584585
cachedThunkValue, err := elem.getValue(i)

testdata/builtin_member_string.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
false
1+
"false true"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
std.member('bar', 'foo')
1+
'%s %s' % [std.member('bar', 'foo'), std.member('foobar', 'foo')]

0 commit comments

Comments
 (0)