03080b3e by astaxie

beego:1.2.0

1 parent b45f0b9b
...@@ -797,14 +797,9 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -797,14 +797,9 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
797 } 797 }
798 798
799 if len(route.params) > 0 { 799 if len(route.params) > 0 {
800 //add url parameters to the query param map
801 values := r.URL.Query()
802 for i, match := range matches[1:] { 800 for i, match := range matches[1:] {
803 values.Add(route.params[i], match)
804 params[route.params[i]] = match 801 params[route.params[i]] = match
805 } 802 }
806 //reassemble query params and add to RawQuery
807 r.URL.RawQuery = url.Values(values).Encode()
808 } 803 }
809 runMethod = p.getRunMethod(r.Method, context, route) 804 runMethod = p.getRunMethod(r.Method, context, route)
810 if runMethod != "" { 805 if runMethod != "" {
......
...@@ -43,6 +43,15 @@ func (this *TestController) GetUrl() { ...@@ -43,6 +43,15 @@ func (this *TestController) GetUrl() {
43 this.Ctx.Output.Body([]byte(this.UrlFor(".Myext"))) 43 this.Ctx.Output.Body([]byte(this.UrlFor(".Myext")))
44 } 44 }
45 45
46 func (t *TestController) GetParams() {
47 t.Ctx.WriteString(t.Ctx.Input.Query(":last") + "+" +
48 t.Ctx.Input.Query(":first") + "+" + t.Ctx.Input.Query("learn"))
49 }
50
51 func (t *TestController) GetManyRouter() {
52 t.Ctx.WriteString(t.Ctx.Input.Query(":id") + t.Ctx.Input.Query(":page"))
53 }
54
46 type ResStatus struct { 55 type ResStatus struct {
47 Code int 56 Code int
48 Msg string 57 Msg string
...@@ -147,21 +156,11 @@ func TestRouteOk(t *testing.T) { ...@@ -147,21 +156,11 @@ func TestRouteOk(t *testing.T) {
147 w := httptest.NewRecorder() 156 w := httptest.NewRecorder()
148 157
149 handler := NewControllerRegistor() 158 handler := NewControllerRegistor()
150 handler.Add("/person/:last/:first", &TestController{}) 159 handler.Add("/person/:last/:first", &TestController{}, "get:GetParams")
151 handler.ServeHTTP(w, r) 160 handler.ServeHTTP(w, r)
152 161 body := w.Body.String()
153 lastNameParam := r.URL.Query().Get(":last") 162 if body != "anderson+thomas+kungfu" {
154 firstNameParam := r.URL.Query().Get(":first") 163 t.Errorf("url param set to [%s];", body)
155 learnParam := r.URL.Query().Get("learn")
156
157 if lastNameParam != "anderson" {
158 t.Errorf("url param set to [%s]; want [%s]", lastNameParam, "anderson")
159 }
160 if firstNameParam != "thomas" {
161 t.Errorf("url param set to [%s]; want [%s]", firstNameParam, "thomas")
162 }
163 if learnParam != "kungfu" {
164 t.Errorf("url param set to [%s]; want [%s]", learnParam, "kungfu")
165 } 164 }
166 } 165 }
167 166
...@@ -171,17 +170,13 @@ func TestManyRoute(t *testing.T) { ...@@ -171,17 +170,13 @@ func TestManyRoute(t *testing.T) {
171 w := httptest.NewRecorder() 170 w := httptest.NewRecorder()
172 171
173 handler := NewControllerRegistor() 172 handler := NewControllerRegistor()
174 handler.Add("/beego:id([0-9]+)-:page([0-9]+).html", &TestController{}) 173 handler.Add("/beego:id([0-9]+)-:page([0-9]+).html", &TestController{}, "get:GetManyRouter")
175 handler.ServeHTTP(w, r) 174 handler.ServeHTTP(w, r)
176 175
177 id := r.URL.Query().Get(":id") 176 body := w.Body.String()
178 page := r.URL.Query().Get(":page")
179 177
180 if id != "32" { 178 if body != "3212" {
181 t.Errorf("url param set to [%s]; want [%s]", id, "32") 179 t.Errorf("url param set to [%s];", body)
182 }
183 if page != "12" {
184 t.Errorf("url param set to [%s]; want [%s]", page, "12")
185 } 180 }
186 } 181 }
187 182
......
...@@ -64,24 +64,30 @@ func GrepFile(patten string, filename string) (lines []string, err error) { ...@@ -64,24 +64,30 @@ func GrepFile(patten string, filename string) (lines []string, err error) {
64 lines = make([]string, 0) 64 lines = make([]string, 0)
65 reader := bufio.NewReader(fd) 65 reader := bufio.NewReader(fd)
66 prefix := "" 66 prefix := ""
67 isLongLine := false
67 for { 68 for {
68 byteLine, isPrefix, er := reader.ReadLine() 69 byteLine, isPrefix, er := reader.ReadLine()
69 if er != nil && er != io.EOF { 70 if er != nil && er != io.EOF {
70 return nil, er 71 return nil, er
71 } 72 }
73 if er == io.EOF {
74 break
75 }
72 line := string(byteLine) 76 line := string(byteLine)
73 if isPrefix { 77 if isPrefix {
74 prefix += line 78 prefix += line
75 continue 79 continue
80 } else {
81 isLongLine = true
76 } 82 }
77 83
78 line = prefix + line 84 line = prefix + line
85 if isLongLine {
86 prefix = ""
87 }
79 if re.MatchString(line) { 88 if re.MatchString(line) {
80 lines = append(lines, line) 89 lines = append(lines, line)
81 } 90 }
82 if er == io.EOF {
83 break
84 }
85 } 91 }
86 return lines, nil 92 return lines, nil
87 } 93 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!