Skip to content

Commit

Permalink
Merge pull request #746 from ReneWerner87/master
Browse files Browse the repository at this point in the history
🦟 Fix star routes
  • Loading branch information
Fenny authored Sep 2, 2020
2 parents 733da09 + ad7f4df commit 29e8f12
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion router.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ func (r *Route) match(path, original string) (match bool, values []string) {
// '*' wildcard matches any path
} else if r.star {
values := getAllocFreeParams(1)
values[0] = original[1:]
if len(original) > 1 {
values[0] = original[1:]
}
return true, values
}
// Does this route have parameters
Expand Down
10 changes: 10 additions & 0 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ func Test_Route_Match_Star(t *testing.T) {
body, err = ioutil.ReadAll(resp.Body)
utils.AssertEqual(t, nil, err, "app.Test(req)")
utils.AssertEqual(t, "test", getString(body))

// without parameter
route := Route{
star: true,
path: "/*",
routeParser: routeParser{},
}
match, params := route.match("", "")
utils.AssertEqual(t, true, match)
utils.AssertEqual(t, []string{""}, params)
}

func Test_Route_Match_Root(t *testing.T) {
Expand Down

1 comment on commit 29e8f12

@Fenny
Copy link
Member Author

@Fenny Fenny commented on 29e8f12 Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 29e8f12 Previous: 225b574 Ratio
Benchmark_Ctx_Accepts 713 ns/op 0 B/op 0 allocs/op 187 ns/op 0 B/op 0 allocs/op 3.81
Benchmark_Ctx_AcceptsCharsets 422 ns/op 0 B/op 0 allocs/op 80.1 ns/op 0 B/op 0 allocs/op 5.27
Benchmark_Ctx_AcceptsEncodings 415 ns/op 0 B/op 0 allocs/op 106 ns/op 0 B/op 0 allocs/op 3.92
Benchmark_Ctx_AcceptsLanguages 193 ns/op 0 B/op 0 allocs/op 80.3 ns/op 0 B/op 0 allocs/op 2.40
Benchmark_Ctx_Append 1075 ns/op 0 B/op 0 allocs/op 280 ns/op 0 B/op 0 allocs/op 3.84
Benchmark_Ctx_Attachment 4435 ns/op 147 B/op 2 allocs/op 375 ns/op 128 B/op 2 allocs/op 11.83
Benchmark_Ctx_BaseURL 454 ns/op 32 B/op 1 allocs/op 92.4 ns/op 32 B/op 1 allocs/op 4.91
Benchmark_Ctx_BodyParser_JSON 2763 ns/op 208 B/op 4 allocs/op 722 ns/op 208 B/op 4 allocs/op 3.83
Benchmark_Ctx_BodyParser_XML 12475 ns/op 1152 B/op 23 allocs/op 3044 ns/op 1152 B/op 23 allocs/op 4.10
Benchmark_Ctx_BodyParser_Form 3614 ns/op 312 B/op 12 allocs/op 1365 ns/op 312 B/op 12 allocs/op 2.65
Benchmark_Ctx_BodyParser_MultipartForm 5367 ns/op 296 B/op 11 allocs/op 1203 ns/op 296 B/op 11 allocs/op 4.46
Benchmark_Ctx_Cookie 407 ns/op 0 B/op 0 allocs/op 153 ns/op 0 B/op 0 allocs/op 2.66
Benchmark_Ctx_Format 490 ns/op 0 B/op 0 allocs/op 177 ns/op 0 B/op 0 allocs/op 2.77
Benchmark_Ctx_Format_HTML 770 ns/op 0 B/op 0 allocs/op 165 ns/op 0 B/op 0 allocs/op 4.67
Benchmark_Ctx_Format_JSON 1002 ns/op 16 B/op 1 allocs/op 420 ns/op 16 B/op 1 allocs/op 2.39
Benchmark_Ctx_Format_XML 8704 ns/op 4464 B/op 7 allocs/op 2132 ns/op 4464 B/op 7 allocs/op 4.08
Benchmark_Ctx_Fresh_StaleEtag 2278 ns/op 0 B/op 0 allocs/op 558 ns/op 0 B/op 0 allocs/op 4.08
Benchmark_Ctx_Fresh_WithNoCache 416 ns/op 0 B/op 0 allocs/op 145 ns/op 0 B/op 0 allocs/op 2.87
Benchmark_Ctx_IPs 870 ns/op 48 B/op 1 allocs/op 208 ns/op 48 B/op 1 allocs/op 4.18
Benchmark_Ctx_Is 203 ns/op 0 B/op 0 allocs/op 75 ns/op 0 B/op 0 allocs/op 2.71
Benchmark_Ctx_Params 193 ns/op 0 B/op 0 allocs/op 68.3 ns/op 0 B/op 0 allocs/op 2.83
Benchmark_Ctx_Protocol 55.3 ns/op 0 B/op 0 allocs/op 17.6 ns/op 0 B/op 0 allocs/op 3.14
Benchmark_Ctx_Subdomains 750 ns/op 64 B/op 1 allocs/op 163 ns/op 64 B/op 1 allocs/op 4.60
Benchmark_Ctx_JSON 1384 ns/op 64 B/op 2 allocs/op 369 ns/op 64 B/op 2 allocs/op 3.75
Benchmark_Ctx_JSONP 1283 ns/op 64 B/op 2 allocs/op 511 ns/op 64 B/op 2 allocs/op 2.51
Benchmark_Ctx_Links 1071 ns/op 0 B/op 0 allocs/op 178 ns/op 0 B/op 0 allocs/op 6.02
Benchmark_Ctx_Render_Engine 5487 ns/op 416 B/op 5 allocs/op 842 ns/op 416 B/op 5 allocs/op 6.52
Benchmark_Ctx_Send 832 ns/op 64 B/op 4 allocs/op 6.81 ns/op 0 B/op 0 allocs/op 122.17
Benchmark_Ctx_Type 223 ns/op 0 B/op 0 allocs/op 70.4 ns/op 0 B/op 0 allocs/op 3.17
Benchmark_Ctx_Type_Charset 465 ns/op 0 B/op 0 allocs/op 159 ns/op 0 B/op 0 allocs/op 2.92
Benchmark_Ctx_Vary 424 ns/op 0 B/op 0 allocs/op 133 ns/op 0 B/op 0 allocs/op 3.19
Benchmark_Ctx_Write 743 ns/op 240 B/op 4 allocs/op 36.6 ns/op 75 B/op 0 allocs/op 20.30
Benchmark_Ctx_SendString_B 37.7 ns/op 0 B/op 0 allocs/op 12.7 ns/op 0 B/op 0 allocs/op 2.97
Benchmark_Ctx_QueryParser 11067 ns/op 912 B/op 39 allocs/op 4232 ns/op 904 B/op 38 allocs/op 2.62
Benchmark_Router_NotFound 1311 ns/op 80 B/op 2 allocs/op 635 ns/op 48 B/op 1 allocs/op 2.06
Benchmark_Router_Handler 1753 ns/op 16 B/op 1 allocs/op 198 ns/op 0 B/op 0 allocs/op 8.85
Benchmark_Router_Handler_Strict_Case 525 ns/op 0 B/op 0 allocs/op 182 ns/op 0 B/op 0 allocs/op 2.88
Benchmark_Router_Chain 1846 ns/op 1 B/op 1 allocs/op 224 ns/op 0 B/op 0 allocs/op 8.24
Benchmark_Router_WithCompression 2627 ns/op 1 B/op 1 allocs/op 221 ns/op 0 B/op 0 allocs/op 11.89
Benchmark_Route_Match 373 ns/op 0 B/op 0 allocs/op 35.4 ns/op 0 B/op 0 allocs/op 10.54
Benchmark_Route_Match_Star 57 ns/op 0 B/op 0 allocs/op 4.8 ns/op 0 B/op 0 allocs/op 11.88
Benchmark_Route_Match_Root 15 ns/op 0 B/op 0 allocs/op 3.94 ns/op 0 B/op 0 allocs/op 3.81
Benchmark_Router_Handler_CaseSensitive 1034 ns/op 0 B/op 0 allocs/op 187 ns/op 0 B/op 0 allocs/op 5.53
Benchmark_Router_Handler_Unescape 1277 ns/op 8 B/op 1 allocs/op 251 ns/op 0 B/op 0 allocs/op 5.09
Benchmark_Router_Handler_StrictRouting 615 ns/op 0 B/op 0 allocs/op 187 ns/op 0 B/op 0 allocs/op 3.29
Benchmark_Router_Github_API 1155259 ns/op 8445 B/op 242 allocs/op 307931 ns/op 0 B/op 0 allocs/op 3.75
Benchmark_Utils_getGroupPath 854 ns/op 96 B/op 2 allocs/op 150 ns/op 96 B/op 2 allocs/op 5.69
Benchmark_Utils_Unescape 154 ns/op 8 B/op 1 allocs/op 54.7 ns/op 8 B/op 1 allocs/op 2.82
Benchmark_Utils_IsNoCache 332 ns/op 0 B/op 0 allocs/op 66.3 ns/op 0 B/op 0 allocs/op 5.01
Benchmark_Middleware_Favicon 759 ns/op 1 B/op 1 allocs/op 118 ns/op 0 B/op 0 allocs/op 6.43

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.