Skip to content

Commit

Permalink
Consider tail after deep wildcard on matching
Browse files Browse the repository at this point in the history
Fixes #23
  • Loading branch information
yugui committed Aug 30, 2015
1 parent a491e6e commit 2a2109d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
9 changes: 7 additions & 2 deletions runtime/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,13 @@ func (p Pattern) Match(components []string, verb string) (map[string]string, err
stack = append(stack, c)
pos++
case utilities.OpPushM:
stack = append(stack, strings.Join(components[pos:], "/"))
pos = len(components)
end := len(components)
if end < pos+p.tailLen {
return nil, ErrNotMatch
}
end -= p.tailLen
stack = append(stack, strings.Join(components[pos:end], "/"))
pos = end
case utilities.OpConcatN:
n := op.operand
l := len(stack) - n
Expand Down
38 changes: 34 additions & 4 deletions runtime/pattern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,18 @@ func TestMatch(t *testing.T) {
ops: []int{int(utilities.OpPushM), anything},
match: []string{"", "abc", "abc/def", "abc/def/ghi"},
},
{
ops: []int{
int(utilities.OpPushM), anything,
int(utilities.OpLitPush), 0,
},
pool: []string{"tail"},
match: []string{"tail", "abc/tail", "abc/def/tail"},
notMatch: []string{
"", "abc", "abc/def",
"tail/extra", "abc/tail/extra", "abc/def/tail/extra",
},
},
{
ops: []int{
int(utilities.OpLitPush), 0,
Expand Down Expand Up @@ -427,6 +439,22 @@ func TestMatchWithBinding(t *testing.T) {
"name": "o/my-bucket/dir/dir2/obj",
},
},
{
ops: []int{
int(utilities.OpLitPush), 0,
int(utilities.OpLitPush), 1,
int(utilities.OpPushM), anything,
int(utilities.OpLitPush), 2,
int(utilities.OpConcatN), 3,
int(utilities.OpCapture), 4,
int(utilities.OpLitPush), 3,
},
pool: []string{"v1", "o", ".ext", "tail", "name"},
path: "v1/o/my-bucket/dir/dir2/obj/.ext/tail",
want: map[string]string{
"name": "o/my-bucket/dir/dir2/obj/.ext",
},
},
{
ops: []int{
int(utilities.OpLitPush), 0,
Expand Down Expand Up @@ -528,11 +556,13 @@ func TestPatternString(t *testing.T) {
int(utilities.OpCapture), 2,
int(utilities.OpLitPush), 3,
int(utilities.OpPushM), anything,
int(utilities.OpConcatN), 2,
int(utilities.OpCapture), 4,
int(utilities.OpLitPush), 4,
int(utilities.OpConcatN), 3,
int(utilities.OpCapture), 6,
int(utilities.OpLitPush), 5,
},
pool: []string{"v1", "buckets", "bucket_name", "objects", "name"},
want: "/v1/{bucket_name=buckets/*}/{name=objects/**}",
pool: []string{"v1", "buckets", "bucket_name", "objects", ".ext", "tail", "name"},
want: "/v1/{bucket_name=buckets/*}/{name=objects/**/.ext}/tail",
},
} {
p, err := NewPattern(validVersion, spec.ops, spec.pool, "")
Expand Down

0 comments on commit 2a2109d

Please sign in to comment.