Skip to content

Commit

Permalink
add text query length check
Browse files Browse the repository at this point in the history
  • Loading branch information
morphy2k committed Jul 17, 2020
1 parent df41844 commit 9d61691
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
12 changes: 12 additions & 0 deletions controller/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ func ItemIndexGET(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
return
}

if l := len(txt); l < 3 || l > 32 {
s := &Status{}
s.BadRequest("Query string has an invalid length").Render(w)
return
}

if !isAlnumBlankPunct(txt) {
s := &Status{}
s.BadRequest("Query string contains invalid characters").Render(w)
Expand Down Expand Up @@ -142,6 +148,12 @@ Loop:
return
}

if l := len(txt); l < 3 || l > 32 {
s := &Status{}
s.BadRequest("Query string has an invalid length").Render(w)
return
}

if !isAlnumBlankPunct(txt) {
s := &Status{}
s.BadRequest("Query string contains invalid characters").Render(w)
Expand Down
36 changes: 36 additions & 0 deletions controller/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ Loop:
return
}

if l := len(txt); l < 3 || l > 32 {
s := &Status{}
s.BadRequest("Query string has an invalid length").Render(w)
return
}

if !isAlnumBlankPunct(txt) {
s := &Status{}
s.BadRequest("Query string contains invalid characters").Render(w)
return
}

result, err = location.GetByText(txt, opts)
if err != nil {
handleError(err, w)
Expand Down Expand Up @@ -204,6 +216,18 @@ Loop:
return
}

if l := len(txt); l < 3 || l > 32 {
s := &Status{}
s.BadRequest("Query string has an invalid length").Render(w)
return
}

if !isAlnumBlankPunct(txt) {
s := &Status{}
s.BadRequest("Query string contains invalid characters").Render(w)
return
}

result, err = feature.GetByText(txt, lID, opts)
if err != nil {
handleError(err, w)
Expand Down Expand Up @@ -423,6 +447,18 @@ Loop:
return
}

if l := len(txt); l < 3 || l > 32 {
s := &Status{}
s.BadRequest("Query string has an invalid length").Render(w)
return
}

if !isAlnumBlankPunct(txt) {
s := &Status{}
s.BadRequest("Query string contains invalid characters").Render(w)
return
}

result, err = featuregroup.GetByText(txt, lID, opts)
if err != nil {
handleError(err, w)
Expand Down

0 comments on commit 9d61691

Please sign in to comment.