1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-24 08:22:21 +02:00

Fixed double padding in Group.File, Group.Add (#1534)

Group.File was padding with g.prefix even though it would later call Group.Add which padded with prefix again - for a total of two times
This commit is contained in:
Ori Shoshan 2020-04-25 20:58:16 +03:00 committed by GitHub
parent 2207c37bf8
commit c29904d81c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -109,7 +109,7 @@ func (g *Group) Static(prefix, root string) {
// File implements `Echo#File()` for sub-routes within the Group.
func (g *Group) File(path, file string) {
g.file(g.prefix+path, file, g.GET)
g.file(path, file, g.GET)
}
// Add implements `Echo#Add()` for sub-routes within the Group.

View File

@ -1,7 +1,9 @@
package echo
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
@ -26,6 +28,19 @@ func TestGroup(t *testing.T) {
g.File("/walle", "_fixture/images//walle.png")
}
func TestGroupFile(t *testing.T) {
e := New()
g := e.Group("/group")
g.File("/walle", "_fixture/images/walle.png")
expectedData, err := ioutil.ReadFile("_fixture/images/walle.png")
assert.Nil(t, err)
req := httptest.NewRequest(http.MethodGet, "/group/walle", nil)
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)
assert.Equal(t, http.StatusOK, rec.Code)
assert.Equal(t, expectedData, rec.Body.Bytes())
}
func TestGroupRouteMiddleware(t *testing.T) {
// Ensure middleware slices are not re-used
e := New()