Skip to content

Commit 9fa7a8e

Browse files
committed
nil check
1 parent 993b575 commit 9fa7a8e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

liquid/condition.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,19 @@ func compareValues(left, right interface{}) (int, error) {
260260
// If one is a number and the other is not, it's a type mismatch for comparison
261261
if leftOk || rightOk {
262262
// Format types nicely for error message
263-
leftType := reflect.TypeOf(left).Name()
264-
if leftType == "" {
265-
leftType = reflect.TypeOf(left).String()
263+
leftType := "nil"
264+
if left != nil {
265+
leftType = reflect.TypeOf(left).Name()
266+
if leftType == "" {
267+
leftType = reflect.TypeOf(left).String()
268+
}
266269
}
267-
rightType := reflect.TypeOf(right).Name()
268-
if rightType == "" {
269-
rightType = reflect.TypeOf(right).String()
270+
rightType := "nil"
271+
if right != nil {
272+
rightType = reflect.TypeOf(right).Name()
273+
if rightType == "" {
274+
rightType = reflect.TypeOf(right).String()
275+
}
270276
}
271277
return 0, NewArgumentError("comparison of " + leftType + " with " + rightType + " failed")
272278
}

0 commit comments

Comments
 (0)