Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions middleware/denco/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const (
// TerminationCharacter is a special character for end of path.
TerminationCharacter = '#'

// SeparatorCharacter separates path segments.
SeparatorCharacter = '/'

// MaxSize is max size of records and internal slice.
MaxSize = (1 << 22) - 1
)
Expand Down Expand Up @@ -420,10 +423,11 @@ type record struct {

// makeRecords returns the records that use to build Double-Arrays.
func makeRecords(srcs []Record) (statics, params []*record) {
spChars := string([]byte{ParamCharacter, WildcardCharacter})
termChar := string(TerminationCharacter)
paramPrefix := string(SeparatorCharacter) + string(ParamCharacter)
wildcardPrefix := string(SeparatorCharacter) + string(WildcardCharacter)
for _, r := range srcs {
if strings.ContainsAny(r.Key, spChars) {
if strings.Contains(r.Key, paramPrefix) || strings.Contains(r.Key, wildcardPrefix) {
r.Key += termChar
params = append(params, &record{Record: r})
} else {
Expand Down
2 changes: 2 additions & 0 deletions middleware/denco/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ func TestRouter_Build_withoutSizeHint(t *testing.T) {
{[]string{"/user"}, 0},
{[]string{"/user/:id"}, 1},
{[]string{"/user/:id/post"}, 1},
{[]string{"/user/:id/post:validate"}, 2},
{[]string{"/user/:id/:group"}, 2},
{[]string{"/user/:id/post/:cid"}, 2},
{[]string{"/user/:id/post/:cid", "/admin/:id/post/:cid"}, 2},
Expand Down Expand Up @@ -487,6 +488,7 @@ func TestRouter_Build_withSizeHint(t *testing.T) {
{"/user/:id", 3, 3},
{"/user/:id/:group", 0, 0},
{"/user/:id/:group", 1, 1},
{"/user/:id/:group:validate", 1, 1},
} {
r := denco.New()
r.SizeHint = v.sizeHint
Expand Down