go-tools icon indicating copy to clipboard operation
go-tools copied to clipboard

staticcheck: detect uses of fmt.Sprintf for URL-like values

Open ainar-g opened this issue 4 years ago • 1 comments

Not sure about the universality on this one, but filing just in case. Also not sure if it's more of a staticcheck or a stylecheck.

var requrl = fmt.Sprintf("http://%s/api/v1/users/%s/comments?q=%s", host, userUUID, query)

This is probably not the best way to create a URL. While the host part may be considered “acceptable”, the query part just looks like bad code to me. Best case scenario: this leads to occasional errors because of bad URLs. Worst case scenario: data leakage due to undervalidated parameters.

I think that this would be much better with *url.URL, url.Values, and path.Join.

ainar-g avatar Apr 14 '20 16:04 ainar-g