File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 11package main
22
33import (
4+ "fmt"
45 "github.com/gin-gonic/gin"
56 "gorm.io/gorm"
67 "net/http"
@@ -34,7 +35,16 @@ func ListFloorsInASpecialHole(c *gin.Context) {
3435 c .String (http .StatusInternalServerError , "failed to make query set: %v" , err )
3536 return
3637 }
37- result := querySet .Order (query .OrderBy + " " + query .Sort ).
38+
39+ validSorts := map [string ]bool {"asc" : true , "desc" : true , "" : true }
40+ validOrderBy := map [string ]bool {"id" : true , "like" : true , "" : true }
41+
42+ if ! validSorts [query .Sort ] || ! validOrderBy [query .OrderBy ] {
43+ c .String (http .StatusBadRequest , "invalid sort or order_by" )
44+ return
45+ }
46+
47+ result := querySet .Order (fmt .Sprintf ("`%s` %s" , query .OrderBy , query .Sort )).
3848 Find (& floors )
3949 if result .Error != nil {
4050 c .String (http .StatusInternalServerError , "failed to query floors: %v" , result .Error )
You can’t perform that action at this time.
0 commit comments