labstack / echo

High performance, minimalist Go web framework
https://echo.labstack.com
MIT License
29.62k stars 2.22k forks source link

When route is registered with empty path it is normalized to `/`. #2616

Closed aldas closed 6 months ago

aldas commented 6 months ago

When route is registered with empty path it is normalized to /. Make sure that returned echo.Route structs reflect that behavior. Internally router has changed ` (empty path) to/for a long time but Route that is returned did not reflect that. Is is problematic withReverse` function that uses empty string as "not found"

Related to #2615

Previous behavior can be seen with this test:

func TestTest(t *testing.T) {
    e := echo.New()

    handler := func(c echo.Context) error {
        return c.String(http.StatusNotImplemented, "Nope")
    }
    r := e.GET("", handler) // path is registered as "" previously. After change `/` is registered
    r.Name = "test"

    existingEmpty := e.Reverse("test")
    assert.Equal(t, "", existingEmpty)

    notExistingEmpty := e.Reverse("not-existing")
    assert.Equal(t, "", notExistingEmpty)
}

whis this change assert.Equal(t, "", existingEmpty) shoulb be change to assert.Equal(t, "/", existingEmpty)to pass the test

codecov[bot] commented 6 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 93.03%. Comparing base (d549290) to head (65d0914).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #2616 +/- ## ======================================= Coverage 93.02% 93.03% ======================================= Files 41 41 Lines 4703 4707 +4 ======================================= + Hits 4375 4379 +4 Misses 236 236 Partials 92 92 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.