beego: fix the tree addTree for regexp
Showing
1 changed file
with
43 additions
and
11 deletions
| ... | @@ -46,22 +46,38 @@ func (t *Tree) addtree(segments []string, tree *Tree, wildcards []string, reg st | ... | @@ -46,22 +46,38 @@ func (t *Tree) addtree(segments []string, tree *Tree, wildcards []string, reg st |
| 46 | } | 46 | } |
| 47 | seg := segments[0] | 47 | seg := segments[0] |
| 48 | iswild, params, regexpStr := splitSegment(seg) | 48 | iswild, params, regexpStr := splitSegment(seg) |
| 49 | if len(segments) == 1 && seg != "" { | 49 | if len(segments) == 1 { |
| 50 | if iswild { | 50 | if iswild { |
| 51 | wildcards = append(wildcards, params...) | ||
| 52 | if regexpStr != "" { | 51 | if regexpStr != "" { |
| 53 | for _, w := range params { | 52 | if reg == "" { |
| 53 | rr := "" | ||
| 54 | for _, w := range wildcards { | ||
| 55 | if w == "." || w == ":" { | ||
| 56 | continue | ||
| 57 | } | ||
| 58 | if w == ":splat" { | ||
| 59 | rr = rr + "(.+)/" | ||
| 60 | } else { | ||
| 61 | rr = rr + "([^/]+)/" | ||
| 62 | } | ||
| 63 | } | ||
| 64 | regexpStr = rr + regexpStr | ||
| 65 | } else { | ||
| 66 | regexpStr = "/" + regexpStr | ||
| 67 | } | ||
| 68 | } else { | ||
| 69 | for _, w := range wildcards { | ||
| 54 | if w == "." || w == ":" { | 70 | if w == "." || w == ":" { |
| 55 | continue | 71 | continue |
| 56 | } | 72 | } |
| 57 | regexpStr = "([^/]+)/" + regexpStr | 73 | regexpStr = "/([^/]+)" + regexpStr |
| 58 | } | 74 | } |
| 59 | } | 75 | } |
| 60 | reg = reg + regexpStr | 76 | reg = reg + regexpStr |
| 61 | filterTreeWithPrefix(tree, wildcards, reg) | 77 | filterTreeWithPrefix(tree, append(wildcards, params...), reg) |
| 62 | t.wildcard = tree | 78 | t.wildcard = tree |
| 63 | } else { | 79 | } else { |
| 64 | filterTreeWithPrefix(tree, wildcards, reg) | 80 | filterTreeWithPrefix(tree, append(wildcards, params...), reg) |
| 65 | t.fixrouters[seg] = tree | 81 | t.fixrouters[seg] = tree |
| 66 | } | 82 | } |
| 67 | return | 83 | return |
| ... | @@ -70,21 +86,37 @@ func (t *Tree) addtree(segments []string, tree *Tree, wildcards []string, reg st | ... | @@ -70,21 +86,37 @@ func (t *Tree) addtree(segments []string, tree *Tree, wildcards []string, reg st |
| 70 | if t.wildcard == nil { | 86 | if t.wildcard == nil { |
| 71 | t.wildcard = NewTree() | 87 | t.wildcard = NewTree() |
| 72 | } | 88 | } |
| 73 | wildcards = append(wildcards) | ||
| 74 | if regexpStr != "" { | 89 | if regexpStr != "" { |
| 75 | for _, w := range params { | 90 | if reg == "" { |
| 91 | rr := "" | ||
| 92 | for _, w := range wildcards { | ||
| 93 | if w == "." || w == ":" { | ||
| 94 | continue | ||
| 95 | } | ||
| 96 | if w == ":splat" { | ||
| 97 | rr = rr + "(.+)/" | ||
| 98 | } else { | ||
| 99 | rr = rr + "([^/]+)/" | ||
| 100 | } | ||
| 101 | } | ||
| 102 | regexpStr = rr + regexpStr | ||
| 103 | } else { | ||
| 104 | regexpStr = "/" + regexpStr | ||
| 105 | } | ||
| 106 | } else { | ||
| 107 | for _, w := range wildcards { | ||
| 76 | if w == "." || w == ":" { | 108 | if w == "." || w == ":" { |
| 77 | continue | 109 | continue |
| 78 | } | 110 | } |
| 79 | regexpStr = "([^/]+)/" + regexpStr | 111 | regexpStr = "/([^/]+)" + regexpStr |
| 80 | } | 112 | } |
| 81 | } | 113 | } |
| 82 | reg = reg + regexpStr | 114 | reg = reg + regexpStr |
| 83 | t.wildcard.addtree(segments[1:], tree, wildcards, reg) | 115 | t.wildcard.addtree(segments[1:], tree, append(wildcards, params...), reg) |
| 84 | } else { | 116 | } else { |
| 85 | subTree := NewTree() | 117 | subTree := NewTree() |
| 86 | t.fixrouters[seg] = subTree | 118 | t.fixrouters[seg] = subTree |
| 87 | subTree.addtree(segments[1:], tree, wildcards, reg) | 119 | subTree.addtree(segments[1:], tree, append(wildcards, params...), reg) |
| 88 | } | 120 | } |
| 89 | } | 121 | } |
| 90 | 122 | ... | ... |
-
Please register or sign in to post a comment