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

Params set to wrong names #672

Closed
victorhaggqvist opened this issue Oct 9, 2016 · 3 comments
Closed

Params set to wrong names #672

victorhaggqvist opened this issue Oct 9, 2016 · 3 comments
Assignees

Comments

@victorhaggqvist
Copy link

Description

Registering two routes on different methods with the same path but different param-name results in the last registered param-name wins.

Example:

GET /:bar
PUT /:foo

No matter if you request GET or PUT /hello param is always set to foo

Expected behavior

Parameter value is set to the registered name

Actual behavior

Parameter value is set to the last registered name on a matching path

Steps to reproduce

With bellow server, run

curl -XGET localhost:4090/hello
curl -XPUT localhost:4090/hello

Server outputs

$ go run main.go
get: ParamNames [foo]
get: ParamValues [hello]
put: ParamNames [foo]
put: ParamValues [hello]

Swap the order of the method registration and params for both will be set to bar

Working code to debug

package main

import (
    "fmt"
    "log"
    "net/http"

    "github.com/labstack/echo"
    "github.com/labstack/echo/engine/standard"
)

func main() {
    e := echo.New()

    e.GET("/:bar", func(ctx echo.Context) error {
        fmt.Printf("get: ParamNames %+v\n", ctx.ParamNames())
        fmt.Printf("get: ParamValues %+v\n", ctx.ParamValues())
        return ctx.String(http.StatusOK, "")
    })
    e.PUT("/:foo", func(ctx echo.Context) error {
        fmt.Printf("put: ParamNames %+v\n", ctx.ParamNames())
        fmt.Printf("put: ParamValues %+v\n", ctx.ParamValues())
        return ctx.String(http.StatusOK, "")
    })

    log.Fatal(e.Run(standard.New(":4090")))
}

Version/commit

2.1, 04e6901

@vishr
Copy link
Member

vishr commented Oct 9, 2016

@victorhaggqvist Can you confirm if this issue is the same as #634 and #479?

@vishr vishr self-assigned this Oct 9, 2016
@victorhaggqvist
Copy link
Author

Judging from the code examples, yes I believe so. Sorry about the dupe, feel free to close this one.

@vishr vishr added the duplicate label Oct 9, 2016
@vishr
Copy link
Member

vishr commented Oct 9, 2016

Tracked in #479

@vishr vishr closed this as completed Oct 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants