Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions liquid/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
}
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions liquid/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions liquid/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down