Skip to content

Commit

Permalink
add check the values array length, avoid panic: index out of range
Browse files Browse the repository at this point in the history
  • Loading branch information
sasukezhang committed Sep 23, 2020
1 parent a8e263c commit 3071f4a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3071f4a

Please sign in to comment.