Skip to content

Commit c29904d

Browse files
author
Ori Shoshan
authored
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
1 parent 2207c37 commit c29904d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

group.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (g *Group) Static(prefix, root string) {
109109

110110
// File implements `Echo#File()` for sub-routes within the Group.
111111
func (g *Group) File(path, file string) {
112-
g.file(g.prefix+path, file, g.GET)
112+
g.file(path, file, g.GET)
113113
}
114114

115115
// Add implements `Echo#Add()` for sub-routes within the Group.

group_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package echo
22

33
import (
4+
"io/ioutil"
45
"net/http"
6+
"net/http/httptest"
57
"testing"
68

79
"github.com/stretchr/testify/assert"
@@ -26,6 +28,19 @@ func TestGroup(t *testing.T) {
2628
g.File("/walle", "_fixture/images//walle.png")
2729
}
2830

31+
func TestGroupFile(t *testing.T) {
32+
e := New()
33+
g := e.Group("/group")
34+
g.File("/walle", "_fixture/images/walle.png")
35+
expectedData, err := ioutil.ReadFile("_fixture/images/walle.png")
36+
assert.Nil(t, err)
37+
req := httptest.NewRequest(http.MethodGet, "/group/walle", nil)
38+
rec := httptest.NewRecorder()
39+
e.ServeHTTP(rec, req)
40+
assert.Equal(t, http.StatusOK, rec.Code)
41+
assert.Equal(t, expectedData, rec.Body.Bytes())
42+
}
43+
2944
func TestGroupRouteMiddleware(t *testing.T) {
3045
// Ensure middleware slices are not re-used
3146
e := New()

0 commit comments

Comments
 (0)