Skip to content

Commit

Permalink
搜索查询sql注入问题修复
Browse files Browse the repository at this point in the history
  • Loading branch information
hulutech-web committed Oct 10, 2024
1 parent ebd2c9e commit abc999d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions paginator.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,25 @@ func (h *HttpResult) SearchByParams(params map[string]string, excepts ...string)
if value == "" || key == "pageSize" || key == "total" || key == "currentPage" || key == "sort" || key == "order" {
continue
} else {
q = q.Where(key+" like ?", "%"+value+"%")
//q:=gorm.Expr(key+" like ?", "%"+value+"%")
//q = q.Where(key+" like ?", "%"+value+"%")
q = q.Raw(key+" like ?", "%"+value+"%").(orm.Query)
}
}
return q
}(query)
return h
}

func (r *HttpResult) ResultPagination(dest any,withes ...string) (http.Response, error) {
func (r *HttpResult) ResultPagination(dest any, withes ...string) (http.Response, error) {
request := r.Context.Request()
pageSize := request.Query("pageSize", "10")
pageSizeInt := cast.ToInt(pageSize)
currentPage := request.Query("currentPage", "1")
currentPageInt := cast.ToInt(currentPage)
total := int64(0)
for _, with := range withes {
r.Query = r.Query.With(with)
r.Query = r.Query.With(with)
}
r.Query.Paginate(currentPageInt, pageSizeInt, dest, &total)

Expand All @@ -70,9 +72,9 @@ func (r *HttpResult) ResultPagination(dest any,withes ...string) (http.Response,
// Corrected links generation
links := Links{
First: proto + request.Origin().Host + URL_PATH + "?pageSize=" + pageSize + "&currentPage=1",
Last: proto + request.Origin().Host + URL_PATH + "?pageSize="+ pageSize + "&currentPage=" + strconv.Itoa(int(total)/pageSizeInt),
Prev: proto + request.Origin().Host + URL_PATH + "?pageSize="+ pageSize + "&currentPage=" + strconv.Itoa(currentPageInt-1),
Next: proto + request.Origin().Host + URL_PATH + "?pageSize="+ pageSize + "&currentPage=" + strconv.Itoa(currentPageInt+1),
Last: proto + request.Origin().Host + URL_PATH + "?pageSize=" + pageSize + "&currentPage=" + strconv.Itoa(int(total)/pageSizeInt),
Prev: proto + request.Origin().Host + URL_PATH + "?pageSize=" + pageSize + "&currentPage=" + strconv.Itoa(currentPageInt-1),
Next: proto + request.Origin().Host + URL_PATH + "?pageSize=" + pageSize + "&currentPage=" + strconv.Itoa(currentPageInt+1),
}

// Corrected total page calculation
Expand Down

0 comments on commit abc999d

Please sign in to comment.