Skip to content

Commit

Permalink
Fix - prevent panic on GetTrimmedParam (gofiber#1593)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneWerner87 authored Oct 25, 2021
1 parent 658b4e4 commit 87b0a15
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion path.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func GetTrimmedParam(param string) string {
start := 0
end := len(param)

if param[start] != paramStarterChar { // is not a param
if end == 0 || param[start] != paramStarterChar { // is not a param
return param
}
start++
Expand Down
4 changes: 3 additions & 1 deletion path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,9 @@ func Test_Path_matchParams(t *testing.T) {

func Test_Utils_GetTrimmedParam(t *testing.T) {
t.Parallel()
res := GetTrimmedParam("*")
res := GetTrimmedParam("")
utils.AssertEqual(t, "", res)
res = GetTrimmedParam("*")
utils.AssertEqual(t, "*", res)
res = GetTrimmedParam(":param")
utils.AssertEqual(t, "param", res)
Expand Down

0 comments on commit 87b0a15

Please sign in to comment.