Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/validate-args-length #2823 #3974

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions js/modules/k6/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
}
}


Check failure on line 63 in js/modules/k6/http/http.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
validateArgCount := func(methodName string,args ...sobek.Value){
if len(args)>2 {
vu.State().Logger.Warningf("%s method has more than two arguments",methodName)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
validateArgCount := func(methodName string,args ...sobek.Value){
if len(args)>2 {
vu.State().Logger.Warningf("%s method has more than two arguments",methodName)
}
}
validateArgCount := func(methodName string,args ...sobek.Value){
if len(args)>2 {
vu.State().Logger.Warnf("http.%s method has more than two arguments",methodName)
}
}

Small suggestion

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do agree with @joanlopez that it's better to add http prefix.

Also, how about changing the message to something more actionable, like http.%s requires two arguments, but %d were provided. Please adjust the input.


mustExport("url", mi.URL)
mustExport("CookieJar", mi.newCookieJar)
mustExport("cookieJar", mi.getVUCookieJar)
Expand All @@ -71,12 +78,18 @@
mustExport("get", func(url sobek.Value, args ...sobek.Value) (*Response, error) {
// http.get(url, params) doesn't have a body argument, so we add undefined
// as the third argument to http.request(method, url, body, params)

// get method should not have more than two arguments
validateArgCount("get",args...)
args = append([]sobek.Value{sobek.Undefined()}, args...)
return mi.defaultClient.Request(http.MethodGet, url, args...)
})
mustExport("head", func(url sobek.Value, args ...sobek.Value) (*Response, error) {
// http.head(url, params) doesn't have a body argument, so we add undefined
// as the third argument to http.request(method, url, body, params)

// head method should not have more than two arguments
validateArgCount("head",args...)
args = append([]sobek.Value{sobek.Undefined()}, args...)
return mi.defaultClient.Request(http.MethodHead, url, args...)
})
Expand Down
Loading