From 7c1502bf044504ff416d390bd747eab317ee0363 Mon Sep 17 00:00:00 2001 From: aa1143 Date: Wed, 23 Sep 2020 21:52:29 +0800 Subject: [PATCH] add check the values array length, avoid panic: index out of range --- context/context.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/context/context.go b/context/context.go index b5f66961..df1cd036 100644 --- a/context/context.go +++ b/context/context.go @@ -1813,8 +1813,11 @@ func (ctx *Context) PostValueDefault(name string, def string) string { if err != nil { return def // it returns "def" even if it's empty here. } + if len(values) > 0 { + return values[len(values)-1] + } - return values[len(values)-1] + return def } // PostValue returns the last parsed form data from POST, PATCH,