-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
URL encoded parameters not working #77
Comments
I'm having the same issue. Did you figure out a workaround? |
@vip8439 no I didnt. I used a POST request instead and put the URL in the POST data |
@philicious I ended up using query parameters instead. My co-worker found (https://golang.org/pkg/net/url/#URL). See the last part of URL. The issue is probably related to that and not gorilla mux itself. If I get the time I'll look at the gorilla mux source and verify whether it's using that. |
I believe this is definietly the reason. I don't see any obvious fix, I'll try to look into it tomorrow. For now, moving the parameter after the |
I think @vip8439 is correct. See http://play.golang.org/p/syfazuTMbV Also see golang/go#7356. It seems to me that gorilla is doing the right thing here. |
Actually, I guess it's not doing the right thing since it ends up responding with 301 instead of 404. So that should probably be fixed. |
I will try to fix this next week or the one after that. But I am a little confused what the correct behaviour should be. Returning 404 is obvious, but the URL should be resolved correctly or this is something we can't / shouldn't change? I'm still not convinced by golang/go#7356 that this is the correct way of handling the Path parameters. Ideas? @kisielk ? |
Same problem here; indeed a bug of the net/url package. I tried to implement a workaround: not using urlencoded |
Are you using base64 encoded strings or base64url encoded strings? You On Monday, May 18, 2015, Rogier Lommers notifications@github.com wrote:
|
Well, my source string is
Now what is the safest way to encode the string so I can decode it in Golang (and how?) |
In Javascript, encode the value with encodeURIComponent and pass it as a query parameter. In the Go code, call req.FormValue("parameterName") to get the decoded value. Passing encoded values as a path element is tricky because of the design error in the net/url package. It's simpler to use query parameters. |
Thanks; working fine with query parameters, instead of path parameters. |
I'm running Go 1.5.1 which claims to have been the issue here #77 (comment) and I am still seeing this issue. Example: // router build
router = mux.NewRouter()
router.HandleFunc("/status", status).Methods("GET")
apiRouter := mux.NewRouter()
apiRouter.HandleFunc("/foo", getFooList).Methods("GET")
apiRouter.HandleFunc("/foo/{bar}", getFoo).Methods("GET")
router.PathPrefix("/foo").Handler(negroni.New(
OAuthRequired(config.OAuth),
negroni.Wrap(apiRouter),
))
url := httptest.NewServer(router).URL
url1 := strings.Join([]string{url, "/foo/bar%2ftest"}, "")
// url2 := strings.Join([]string{url, "/foo/bar.test}", "")
req, err := http.NewRequest("GET", url1, nil)
client := &http.Client{}
req, err := client.Do(req)
fmt.Printf("Req: %+v \n Err: %+v \n", req, err) If I use |
Sorry to bring this up again. But this is still a bug. @garyburd can you explain this a little more? "Passing encoded values as a path element is tricky because of the design error in the net/url package. It's simpler to use query parameters." |
@highway900 Unescaping a path to a string is a lossy operation. A specific example is that it's not possible to distinguish a "/" in a path element from a "/" used as a path element separator. A workaround was added in 0a192a1 and updated in c9183aa. |
I solved this problem like this: This only works if the parameter goes last. |
Can also use
Have to then use url.QueryUnescape in the route |
url.QueryUnescape doesn't seem to work either ;(. |
@d681 - please open a new issue with your example, as "doesn't seem to work" doesn't help us help you :) |
Turns out I had an outdated version of Gorilla mux. Updating the package made it work. Thanks and sorry for the bother. |
if you have sth like
Router.HandleFunc("/bla/{foo}", someHandler)
the "foo" parameter cant be an URL-encoded string like "hmm%2Fstrange"
The text was updated successfully, but these errors were encountered: