diff --git a/liquid/context.go b/liquid/context.go index 5736c6a..0f3828c 100644 --- a/liquid/context.go +++ b/liquid/context.go @@ -297,11 +297,13 @@ func (c *Context) HandleError(err error, lineNumber *int) string { if _, ok := err.(*StandardError); !ok { if _, ok := err.(*ArgumentError); !ok { if _, ok := err.(*UndefinedVariable); !ok { - if _, ok := err.(*DisabledError); !ok { - if _, ok := err.(*MemoryError); !ok { - if _, ok := err.(*FileSystemError); !ok { - if _, ok := err.(*StackLevelError); !ok { - liquidErr = NewInternalError("internal") + if _, ok := err.(*UndefinedFilter); !ok { + if _, ok := err.(*DisabledError); !ok { + if _, ok := err.(*MemoryError); !ok { + if _, ok := err.(*FileSystemError); !ok { + if _, ok := err.(*StackLevelError); !ok { + liquidErr = NewInternalError("internal") + } } } } @@ -396,7 +398,9 @@ func (c *Context) HandleError(err error, lineNumber *int) string { func (c *Context) Invoke(method string, obj interface{}, args ...interface{}) interface{} { result, err := c.Strainer().Invoke(method, append([]interface{}{obj}, args...)...) if err != nil { - // Handle error + if c.strictFilters { + panic(err) + } return obj } return ToLiquid(result) diff --git a/liquid/context_test.go b/liquid/context_test.go index 8de2830..296891a 100644 --- a/liquid/context_test.go +++ b/liquid/context_test.go @@ -197,6 +197,32 @@ func TestContextStrictVariables(t *testing.T) { }() } +func TestContextInvokeStrictFiltersUnknownPanics(t *testing.T) { + ctx := NewContext() + ctx.SetStrictFilters(true) + + defer func() { + if r := recover(); r == nil { + t.Fatal("Expected panic for undefined filter in strict mode") + } else { + if _, ok := r.(*UndefinedFilter); !ok { + t.Fatalf("Expected UndefinedFilter panic, got %T", r) + } + } + }() + + ctx.Invoke("NonexistentFilter", "arg") +} + +func TestContextInvokeNonStrictFiltersUnknownReturnsOriginal(t *testing.T) { + ctx := NewContext() + + result := ctx.Invoke("NonexistentFilter", "arg") + if result != "arg" { + t.Errorf("Expected original object in non-strict mode, got %v", result) + } +} + func TestContextResourceLimits(t *testing.T) { ctx := NewContext() rl := ctx.ResourceLimits() diff --git a/liquid/variable.go b/liquid/variable.go index 6b673a8..e2e80c1 100644 --- a/liquid/variable.go +++ b/liquid/variable.go @@ -408,6 +408,8 @@ func (v *Variable) RenderToOutputBuffer(context TagContext, output *string) { err = e case *StackLevelError: err = e + case *UndefinedFilter: + err = e case *Error: err = e case error: