Echo: URL Path Parameter get bugged

Created on 16 Dec 2019  路  9Comments  路  Source: labstack/echo

Issue Description

Context#Param(name string) doesn't work in certain constellations.

Checklist

  • [ X ] Dependencies installed
  • [ X ] No typos
  • [ X ] Searched existing issues and docs

Expected behaviour

The following code yields results for handler1 (using c.Param("page")) and for handler3 and handler4 (using c.Param("id"))

    mux.GET("path/:page", handler1)
    mux.POST("path", handler2)
    mux.PATCH("path/:id", handler3)
    mux.DELETE("path/:id", handler4)

Actual behaviour

The following code yields and empty string for handler3 and handler4 (using c.Param("id")).

    mux.GET("path/:page", handler1)
    mux.POST("path", handler2)
    mux.PATCH("path/:id", handler3)
    mux.DELETE("path/:id", handler4)

The following code yields and empty string for handler1 (using c.Param("page")).

    mux.POST("path", handler2)
    mux.PATCH("path/:id", handler3)
    mux.DELETE("path/:id", handler4)
        mux.GET("path/:page", handler1)

Steps to reproduce

func handler3(c echo.Context) error {
    idParam := c.Param("id")
        log.Println(idParam);
}

Working code to debug

See above

Version/commit

Latest (github.com/labstack/echo)

wontfix

All 9 comments

After reading through this issue I found that that all parameter names for the same endpoint need to be the same (which was my temporary fix).
It would certainly be advisable to mention this in the docs

I am seeing the same issue and having the workaround as @SaubereSache mentioned. However, it makes the code harder to maintain. It would be good if it can be fixed.

Refer #1467 I think your issue should be fixed starting from version 4.1.13

Works, thanks for the fix :)

Regression, broke again as of v4.1.16 (@asahasrabuddhe @vishr)

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Is it still actual?

We ran into this bug again using v4.1.16 on one of our projects. The tests that were added as part of the merge for #1467 only test the GET and POST verbs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

absinsekt picture absinsekt  路  4Comments

runner-mei picture runner-mei  路  4Comments

montanaflynn picture montanaflynn  路  3Comments

arun0009 picture arun0009  路  3Comments

ellisonleao picture ellisonleao  路  3Comments