Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Merge pull request #179 from majestrate/search-fix

remove sql injections
Cette révision appartient à :
ewhal 2017-05-09 00:45:04 +10:00 révisé par GitHub
révision db35ce27ff

Voir le fichier

@ -46,12 +46,33 @@ func SearchByQuery(r *http.Request, pagenum int) (SearchParam, []model.Torrents,
searchCatId = html.EscapeString(catsSplit[0]) searchCatId = html.EscapeString(catsSplit[0])
searchSubCatId = html.EscapeString(catsSplit[1]) searchSubCatId = html.EscapeString(catsSplit[1])
} }
if search_param.Sort == "" {
switch search_param.Sort {
case "torrent_name":
search_param.Sort = "torrent_name"
break
case "date":
search_param.Sort = "date"
break
case "downloads":
search_param.Sort = "downloads"
break
case "filesize":
search_param.Sort = "filesize"
case "torrent_id":
default:
search_param.Sort = "torrent_id" search_param.Sort = "torrent_id"
} }
if search_param.Order == "" {
switch search_param.Order {
case "asc":
search_param.Order = "asc"
break
case "desc":
default:
search_param.Order = "desc" search_param.Order = "desc"
} }
order_by := search_param.Sort + " " + search_param.Order order_by := search_param.Sort + " " + search_param.Order
parameters := torrentService.WhereParams{} parameters := torrentService.WhereParams{}
@ -83,8 +104,9 @@ func SearchByQuery(r *http.Request, pagenum int) (SearchParam, []model.Torrents,
// punctuation characters. // punctuation characters.
continue continue
} }
conditions = append(conditions, "torrent_name LIKE % ? %") // TODO: make this faster ?
parameters.Params = append(parameters.Params, searchQuerySplit[i]) conditions = append(conditions, "torrent_name ILIKE ?")
parameters.Params = append(parameters.Params, "%"+searchQuerySplit[i]+"%")
} }
parameters.Conditions = strings.Join(conditions[:], " AND ") parameters.Conditions = strings.Join(conditions[:], " AND ")