summaryrefslogtreecommitdiffstats
path: root/hugolib/shortcode.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2015-08-07 19:21:26 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2015-08-07 19:21:26 +0200
commit35bb72c83efbdd868af9b32af034993c245b4584 (patch)
tree8eb5e222cdad16384b810d0a93d4e73578065eb7 /hugolib/shortcode.go
parent2805a6f80e1e68d2d3df4ba7f63e7455c3802899 (diff)
Do not panic on index out of range in shortcode.Get
Fixes #1335
Diffstat (limited to 'hugolib/shortcode.go')
-rw-r--r--hugolib/shortcode.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go
index ac1a7f1d3..8b445f0db 100644
--- a/hugolib/shortcode.go
+++ b/hugolib/shortcode.go
@@ -60,7 +60,13 @@ func (scp *ShortcodeWithPage) Get(key interface{}) interface{} {
if reflect.TypeOf(scp.Params).Kind() == reflect.Map {
return "error: cannot access named params by position"
} else if reflect.TypeOf(scp.Params).Kind() == reflect.Slice {
- x = reflect.ValueOf(scp.Params).Index(int(reflect.ValueOf(key).Int()))
+ idx := int(reflect.ValueOf(key).Int())
+ ln := reflect.ValueOf(scp.Params).Len()
+ if idx > ln-1 {
+ helpers.DistinctErrorLog.Printf("No shortcode param at .Get %d in page %s, have params: %v", idx, scp.Page.FullFilePath(), scp.Params)
+ return fmt.Sprintf("error: index out of range for positional param at position %d", idx)
+ }
+ x = reflect.ValueOf(scp.Params).Index(idx)
}
case string:
if reflect.TypeOf(scp.Params).Kind() == reflect.Map {