Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nil reference in if statement panics #34

Open
sam-at-luther opened this issue Mar 11, 2020 · 0 comments
Open

Nil reference in if statement panics #34

sam-at-luther opened this issue Mar 11, 2020 · 0 comments

Comments

@sam-at-luther
Copy link

Outside of an if statement raymond will silently ignore invalid references within a template. Within the condition of an if, raymond will panic on an invalid reference:

Example:

package main

import (
	"fmt"

	"github.com/aymerick/raymond"
)

func main() {
	tpl := `{{#if wat[0].fnord}}wat{{/if}}`

	ctx := map[string]string{}

	result, err := raymond.Render(tpl, ctx)
	if err != nil {
		panic("Please report a bug :)")
	}

	fmt.Print(result)
}

Results in:

panic: runtime error: invalid memory address or nil pointer dereference [recovered]                                                    
        panic: runtime error: invalid memory address or nil pointer dereference                                                        
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x1103ed6]                                                               
                                                                                                                                       
goroutine 1 [running]:                                                                                                                 
github.com/aymerick/raymond.errRecover(0xc00009fee0)                                                                                   
        /Users/swood/work/src/github.com/aymerick/raymond/template.go:232 +0xf5                                                        
panic(0x112e360, 0x1258f40)                                                                                                            
        /usr/local/Cellar/go/1.13.4/libexec/src/runtime/panic.go:679 +0x1b2                           
github.com/aymerick/raymond.(*Options).HashProp(...)                                                                                   
        /Users/swood/work/src/github.com/aymerick/raymond/helper.go:145                                                                
github.com/aymerick/raymond.(*Options).isIncludableZero(...)                                                                           
        /Users/swood/work/src/github.com/aymerick/raymond/helper.go:281                                                                
github.com/aymerick/raymond.ifHelper(0x0, 0x0, 0x0, 0x0, 0x0)                                                                          
        /Users/swood/work/src/github.com/aymerick/raymond/helper.go:298 +0x26                                                          
reflect.Value.call(0x112a860, 0x115d508, 0x13, 0x11549b2, 0x4, 0xc0000672f0, 0x2, 0x2, 0xc00009f970, 0xc00009f970, ...)
        /usr/local/Cellar/go/1.13.4/libexec/src/reflect/value.go:460 +0x5f6                              
reflect.Value.Call(0x112a860, 0x115d508, 0x13, 0xc0000672f0, 0x2, 0x2, 0x3, 0x1159af0, 0x203000)
        /usr/local/Cellar/go/1.13.4/libexec/src/reflect/value.go:321 +0xb4                                                             
github.com/aymerick/raymond.(*evalVisitor).callFunc(0xc0000c6000, 0x1159aea, 0x2, 0x112a860, 0x115d508, 0x13, 0xc0000672c0, 0x115d508, 0x13, 0x0)
        /Users/swood/work/src/github.com/aymerick/raymond/eval.go:642 +0x46e
github.com/aymerick/raymond.(*evalVisitor).callHelper(0xc0000c6000, 0x1159aea, 0x2, 0x112a860, 0x115d508, 0x13, 0xc00008eb90, 0x1, 0x0) 
        /Users/swood/work/src/github.com/aymerick/raymond/eval.go:649 +0x8c                                                            
github.com/aymerick/raymond.(*evalVisitor).VisitExpression(0xc0000c6000, 0xc00008eb90, 0x0, 0x0)                                       
        /Users/swood/work/src/github.com/aymerick/raymond/eval.go:916 +0x32d                                                           
github.com/aymerick/raymond/ast.(*Expression).Accept(...)                                                                              
        /Users/swood/work/src/github.com/aymerick/raymond/ast/node.go:400                                                              
github.com/aymerick/raymond.(*evalVisitor).VisitBlock(0xc0000c6000, 0xc00008eb40, 0xc00008a2b5, 0x1260f20)
        /Users/swood/work/src/github.com/aymerick/raymond/eval.go:822 +0xb0                                                            
github.com/aymerick/raymond/ast.(*BlockStatement).Accept(0xc00008eb40, 0x1182480, 0xc0000c6000, 0x1148dc0, 0xc00009fdc8)
        /Users/swood/work/src/github.com/aymerick/raymond/ast/node.go:259 +0x3b                                                        
github.com/aymerick/raymond.(*evalVisitor).VisitProgram(0xc0000c6000, 0xc000086f00, 0xc000066f90, 0x0)
        /Users/swood/work/src/github.com/aymerick/raymond/eval.go:783 +0x176                                                           
github.com/aymerick/raymond/ast.(*Program).Accept(...)                                                                                 
        /Users/swood/work/src/github.com/aymerick/raymond/ast/node.go:181                                                              
github.com/aymerick/raymond.(*Template).ExecWith(0xc000088500, 0x112b8e0, 0xc000066f90, 0x0, 0x0, 0x0, 0x0, 0x0)                       
        /Users/swood/work/src/github.com/aymerick/raymond/template.go:220 +0xf3                                                        
github.com/aymerick/raymond.(*Template).Exec(...)                                                                                      
        /Users/swood/work/src/github.com/aymerick/raymond/template.go:194
github.com/aymerick/raymond.Render(0x1159ae7, 0x1e, 0x112b8e0, 0xc000066f90, 0xc000062058, 0x0, 0x0, 0x0)                              
        /Users/swood/work/src/github.com/aymerick/raymond/raymond.go:15 +0x78                                                          
main.main()                                                                                                                            
        /tmp/raymondpanic/main.go:14 +0x54                                               
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant