Fix incorrect conversion between integer types
This commit is contained in:
parent
2f7ad3ac73
commit
897d8644c5
2 changed files with 16 additions and 2 deletions
|
@ -72,7 +72,21 @@ func QueryStringParamList(r *http.Request, param string) []string {
|
|||
|
||||
// QueryIntParam returns a query string parameter as integer.
|
||||
func QueryIntParam(r *http.Request, param string, defaultValue int) int {
|
||||
return int(QueryInt64Param(r, param, int64(defaultValue)))
|
||||
value := r.URL.Query().Get(param)
|
||||
if value == "" {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
val, err := strconv.ParseInt(value, 10, 0)
|
||||
if err != nil {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
if val < 0 {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
return int(val)
|
||||
}
|
||||
|
||||
// QueryInt64Param returns a query string parameter as int64.
|
||||
|
|
|
@ -74,7 +74,7 @@ func (s *SettingsForm) Validate() error {
|
|||
|
||||
// NewSettingsForm returns a new SettingsForm.
|
||||
func NewSettingsForm(r *http.Request) *SettingsForm {
|
||||
entriesPerPage, err := strconv.ParseInt(r.FormValue("entries_per_page"), 10, 64)
|
||||
entriesPerPage, err := strconv.ParseInt(r.FormValue("entries_per_page"), 10, 0)
|
||||
if err != nil {
|
||||
entriesPerPage = 0
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue