@@ -138,7 +138,7 @@ ngx_http_google_request_parse_scholar(ngx_http_request_t * r,
138
138
{
139
139
if (ngx_http_google_request_parse_cookie_conf (r , ctx )) return NGX_ERROR ;
140
140
141
- if (ctx -> uri -> len == 12 && ctx -> args ) {
141
+ if (ctx -> uri -> len == 12 && ctx -> args && ctx -> args -> nelts ) {
142
142
143
143
u_char * refer = ctx -> uri -> data + 9 ;
144
144
@@ -183,10 +183,18 @@ ngx_http_google_request_parse_scholar(ngx_http_request_t * r,
183
183
184
184
if (!ngx_strncasecmp (ctx -> uri -> data , (u_char * )"/scholar" , 8 ))
185
185
{
186
+ ngx_str_t uri = * ctx -> uri ;
187
+
188
+ // strip "/scholar" uri
189
+ uri .data += 8 ;
190
+ uri .len -= 8 ;
191
+
186
192
ngx_uint_t i , strip = 1 ;
187
193
ngx_keyval_t * kv , * hd = ctx -> args -> elts ;
188
194
189
- for (i = 0 ; i < ctx -> args -> nelts ; i ++ ) {
195
+ // traverse args
196
+ for (i = 0 ; i < ctx -> args -> nelts ; i ++ )
197
+ {
190
198
kv = hd + i ;
191
199
if (!kv -> key .len ) continue ;
192
200
if (kv -> key .len == 1 && * kv -> key .data == 'q' )
@@ -206,15 +214,12 @@ ngx_http_google_request_parse_scholar(ngx_http_request_t * r,
206
214
207
215
}
208
216
209
- if (ctx -> uri -> len > 8 ) switch (ctx -> uri -> data [ 8 ] ) {
217
+ if (uri . len ) switch (* uri . data ) {
210
218
case '?' : case '/' : break ;
211
219
default : strip = 0 ; break ;
212
220
}
213
221
214
- if (strip ) {
215
- ctx -> uri -> data += 8 ;
216
- ctx -> uri -> len -= 8 ;
217
- }
222
+ if (strip ) * ctx -> uri = uri ;
218
223
}
219
224
}
220
225
0 commit comments