File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ const (
17
17
// TerminationCharacter is a special character for end of path.
18
18
TerminationCharacter = '#'
19
19
20
+ // SeparatorCharacter separates path segments.
21
+ SeparatorCharacter = '/'
22
+
20
23
// MaxSize is max size of records and internal slice.
21
24
MaxSize = (1 << 22 ) - 1
22
25
)
@@ -420,10 +423,11 @@ type record struct {
420
423
421
424
// makeRecords returns the records that use to build Double-Arrays.
422
425
func makeRecords (srcs []Record ) (statics , params []* record ) {
423
- spChars := string ([]byte {ParamCharacter , WildcardCharacter })
424
426
termChar := string (TerminationCharacter )
427
+ paramPrefix := string (SeparatorCharacter ) + string (ParamCharacter )
428
+ wildcardPrefix := string (SeparatorCharacter ) + string (WildcardCharacter )
425
429
for _ , r := range srcs {
426
- if strings .ContainsAny (r .Key , spChars ) {
430
+ if strings .Contains (r .Key , paramPrefix ) || strings . Contains ( r . Key , wildcardPrefix ) {
427
431
r .Key += termChar
428
432
params = append (params , & record {Record : r })
429
433
} else {
Original file line number Diff line number Diff line change @@ -448,6 +448,7 @@ func TestRouter_Build_withoutSizeHint(t *testing.T) {
448
448
{[]string {"/user" }, 0 },
449
449
{[]string {"/user/:id" }, 1 },
450
450
{[]string {"/user/:id/post" }, 1 },
451
+ {[]string {"/user/:id/post:validate" }, 2 },
451
452
{[]string {"/user/:id/:group" }, 2 },
452
453
{[]string {"/user/:id/post/:cid" }, 2 },
453
454
{[]string {"/user/:id/post/:cid" , "/admin/:id/post/:cid" }, 2 },
@@ -487,6 +488,7 @@ func TestRouter_Build_withSizeHint(t *testing.T) {
487
488
{"/user/:id" , 3 , 3 },
488
489
{"/user/:id/:group" , 0 , 0 },
489
490
{"/user/:id/:group" , 1 , 1 },
491
+ {"/user/:id/:group:validate" , 1 , 1 },
490
492
} {
491
493
r := denco .New ()
492
494
r .SizeHint = v .sizeHint
You can’t perform that action at this time.
0 commit comments