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

URLParam need to check is nil or not #426

Closed
powxiao opened this issue May 28, 2019 · 5 comments
Closed

URLParam need to check is nil or not #426

powxiao opened this issue May 28, 2019 · 5 comments

Comments

@powxiao
Copy link

powxiao commented May 28, 2019

the route like below,

func (h *PostSessionOperate) URL() string {
	return "/api/v1/cps/sessions/{session_id}/operate"
}

and post request as localhost:8080/api/v1/cps/sessions//operate, then in function

func (x *Context) URLParam(key string) string {
	for k := len(x.URLParams.Keys) - 1; k >= 0; k-- {
		if x.URLParams.Keys[k] == key {
			return x.URLParams.Values[k]
		}
	}
	return ""
}

x.URLParams.Values is nil , but k ==0 , use x.URLParams.Values[0] panic occurs.

image

@DCRcoder
Copy link

meet same problem
if server get /api/v1/cps/sessions//operate request like this example. there will be panic.
is this expect?

@rof20004
Copy link

rof20004 commented Oct 20, 2019

@DCRcoder @powxiao your implementation got panic?

I think URLParams.Keys will not be nil, because is not a pointer.

@DCRcoder
Copy link

yes URLParams.Keys existed but URLParams.values not
there a route like this

r.Get('/url/{param:(\\w+)}/test', xxx)

if web get request '/url//test' that missing url param, URLParams.values will panic because no value in there.

@DCRcoder @powxiao your implementation got panic?

I think URLParams.Keys will not be nil, because is not a pointer.

@moorereason
Copy link

I was only able to reproduce this panic when using a regexp param. A regular param (like the OP) doesn't trigger a panic for me.

I've pushed a PR that adds a failing test.

@pkieltyka
Copy link
Member

thanks for the report + suggestions -- fixed: 3658d98

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants