mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
fix #1681
This commit is contained in:
parent
ba30ef4de1
commit
82c5dfea50
|
@ -1793,7 +1793,7 @@ func (ctx *Context) PostValues(name string) ([]string, error) {
|
|||
// See ErrEmptyForm, ErrNotFound and ErrEmptyFormField respectfully.
|
||||
func (ctx *Context) PostValueMany(name string) (string, error) {
|
||||
values, err := ctx.PostValues(name)
|
||||
if err != nil {
|
||||
if err != nil || len(values) == 0 {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
@ -1806,14 +1806,11 @@ func (ctx *Context) PostValueMany(name string) (string, error) {
|
|||
// If not found then "def" is returned instead.
|
||||
func (ctx *Context) PostValueDefault(name string, def string) string {
|
||||
values, err := ctx.PostValues(name)
|
||||
if err != nil {
|
||||
if err != nil || len(values) == 0 {
|
||||
return def // it returns "def" even if it's empty here.
|
||||
}
|
||||
if len(values) > 0 {
|
||||
return values[len(values)-1]
|
||||
}
|
||||
|
||||
return def
|
||||
return values[len(values)-1]
|
||||
}
|
||||
|
||||
// PostValue returns the last parsed form data from POST, PATCH,
|
||||
|
@ -1836,8 +1833,8 @@ func (ctx *Context) PostValueTrim(name string) string {
|
|||
// See ErrEmptyForm, ErrNotFound and ErrEmptyFormField respectfully.
|
||||
func (ctx *Context) PostValueInt(name string) (int, error) {
|
||||
values, err := ctx.PostValues(name)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
if err != nil || len(values) == 0 {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return strconv.Atoi(values[len(values)-1])
|
||||
|
@ -1861,8 +1858,8 @@ func (ctx *Context) PostValueIntDefault(name string, def int) int {
|
|||
// See ErrEmptyForm, ErrNotFound and ErrEmptyFormField respectfully.
|
||||
func (ctx *Context) PostValueInt64(name string) (int64, error) {
|
||||
values, err := ctx.PostValues(name)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
if err != nil || len(values) == 0 {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return strconv.ParseInt(values[len(values)-1], 10, 64)
|
||||
|
@ -1886,8 +1883,8 @@ func (ctx *Context) PostValueInt64Default(name string, def int64) int64 {
|
|||
// See ErrEmptyForm, ErrNotFound and ErrEmptyFormField respectfully.
|
||||
func (ctx *Context) PostValueFloat64(name string) (float64, error) {
|
||||
values, err := ctx.PostValues(name)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
if err != nil || len(values) == 0 {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return strconv.ParseFloat(values[len(values)-1], 64)
|
||||
|
@ -1912,7 +1909,7 @@ func (ctx *Context) PostValueFloat64Default(name string, def float64) float64 {
|
|||
// See ErrEmptyForm, ErrNotFound and ErrEmptyFormField respectfully.
|
||||
func (ctx *Context) PostValueBool(name string) (bool, error) {
|
||||
values, err := ctx.PostValues(name)
|
||||
if err != nil {
|
||||
if err != nil || len(values) == 0 {
|
||||
return false, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user