Skip to content

Commit

Permalink
Add non-empty checks to query parameter parsing (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
nevali committed Aug 14, 2017
1 parent 7942dd5 commit e9be1d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
12 changes: 6 additions & 6 deletions quilt/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ spindle_query_request(struct query_struct *dest, QUILTREQ *request, const char *
const char *t;

t = quilt_request_getparam(request, "q");
if(t)
if(t && t[0])
{
dest->explicit = 1;
quilt_canon_set_param(request->canonical, "q", t);
}
t = quilt_request_getparam(request, "class");
if(t)
if(t && t[0])
{
dest->explicit = 1;
quilt_canon_set_param(request->canonical, "class", t);
Expand All @@ -73,7 +73,7 @@ spindle_query_request(struct query_struct *dest, QUILTREQ *request, const char *
dest->text = quilt_request_getparam(request, "q");
dest->lang = quilt_request_getparam(request, "lang");
dest->media = quilt_request_getparam(request, "media");
if(dest->text || dest->lang || dest->media)
if((dest->text && dest->text[0]) || (dest->lang && dest->lang[0]) || (dest->media && dest->media[0]))
{
dest->explicit = 1;
}
Expand All @@ -92,7 +92,7 @@ spindle_query_request(struct query_struct *dest, QUILTREQ *request, const char *
}

dest->type = quilt_request_getparam(request, "type");
if(dest->type)
if(dest->type && dest->type[0])
{
dest->explicit = 1;
}
Expand All @@ -101,7 +101,7 @@ spindle_query_request(struct query_struct *dest, QUILTREQ *request, const char *
quilt_canon_set_param(request->canonical, "type", dest->type);
}
t = quilt_request_getparam(request, "mode");
if(t)
if(t && t[0])
{
if(!strcmp(t, "autocomplete"))
{
Expand All @@ -117,7 +117,7 @@ spindle_query_request(struct query_struct *dest, QUILTREQ *request, const char *
}
}
t = quilt_request_getparam(request, "score");
if(t)
if(t && t[0])
{
dest->score = atoi(t);
quilt_canon_set_param(request->canonical, "score", t);
Expand Down
19 changes: 14 additions & 5 deletions quilt/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,16 @@ spindle_add_concrete(QUILTREQ *request)
static int
spindle_request_is_query_(QUILTREQ *request)
{
const char *t;

if(!request->home)
{
return 0;
}
if(quilt_request_getparam(request, "q") ||
quilt_request_getparam(request, "media") ||
quilt_request_getparam(request, "for") ||
quilt_request_getparam(request, "type"))
if(((t = quilt_request_getparam(request, "q")) && t[0]) ||
((t = quilt_request_getparam(request, "media")) && t[0]) ||
((t = quilt_request_getparam(request, "for")) && t[0]) ||
((t = quilt_request_getparam(request, "type")) && t[0]))
{
request->index = 1;
request->home = 0;
Expand Down Expand Up @@ -269,11 +271,18 @@ spindle_request_is_partition_(QUILTREQ *request, char **qclass)
static const char *
spindle_request_is_lookup_(QUILTREQ *request)
{
const char *t;

if(!request->home)
{
return NULL;
}
return quilt_request_getparam(request, "uri");
t = quilt_request_getparam(request, "uri");
if(t && t[0])
{
return t;
}
return NULL;
}

static struct spindle_dynamic_endpoint *
Expand Down

0 comments on commit e9be1d1

Please sign in to comment.