| 953 | } |
| 954 | |
| 955 | func TestEchoServeHTTPPathEncoding(t *testing.T) { |
| 956 | e := New() |
| 957 | e.GET("/with/slash", func(c *Context) error { |
| 958 | return c.String(http.StatusOK, "/with/slash") |
| 959 | }) |
| 960 | e.GET("/:id", func(c *Context) error { |
| 961 | return c.String(http.StatusOK, c.Param("id")) |
| 962 | }) |
| 963 | |
| 964 | var testCases = []struct { |
| 965 | name string |
| 966 | whenURL string |
| 967 | expectURL string |
| 968 | expectStatus int |
| 969 | }{ |
| 970 | { |
| 971 | name: "url with encoding is not decoded for routing", |
| 972 | whenURL: "/with%2Fslash", |
| 973 | expectURL: "with%2Fslash", // `%2F` is not decoded to `/` for routing |
| 974 | expectStatus: http.StatusOK, |
| 975 | }, |
| 976 | { |
| 977 | name: "url without encoding is used as is", |
| 978 | whenURL: "/with/slash", |
| 979 | expectURL: "/with/slash", |
| 980 | expectStatus: http.StatusOK, |
| 981 | }, |
| 982 | } |
| 983 | |
| 984 | for _, tc := range testCases { |
| 985 | t.Run(tc.name, func(t *testing.T) { |
| 986 | req := httptest.NewRequest(http.MethodGet, tc.whenURL, nil) |
| 987 | rec := httptest.NewRecorder() |
| 988 | |
| 989 | e.ServeHTTP(rec, req) |
| 990 | |
| 991 | assert.Equal(t, tc.expectStatus, rec.Code) |
| 992 | assert.Equal(t, tc.expectURL, rec.Body.String()) |
| 993 | }) |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | func TestEchoGroup(t *testing.T) { |
| 998 | e := New() |