Skip to content

Commit

Permalink
handle ? and = in query value
Browse files Browse the repository at this point in the history
  • Loading branch information
dj2 committed Sep 2, 2010
1 parent 50a3317 commit a5f6361
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
18 changes: 13 additions & 5 deletions ext/pr_query_parser.c
Expand Up @@ -93,27 +93,35 @@ pr_query_parser(VALUE self, VALUE query_string, VALUE delim)

params = rb_hash_new();
qs = strdup(RSTRING_PTR(query_string));
for (s = qs, p = qs, key = qs; *p != 0; p++)
for (s = qs, p = qs; *p != 0; p++)
{
if (*p == delimiter)
{
*p = 0;
if (key != NULL)
{
*p = 0;
pr_set_param(params, key, s);
key = NULL;
}
else
{
pr_set_param(params, s, s);
}
s = (p + 1);
key = s;
}
else if (*p == '=')
else if ((*p == '=') && (key == NULL))
{
*p = 0;
key = s;
s = (p + 1);
}
}

if (key != NULL) pr_set_param(params, key, s);
if (s != NULL)
{
if (key != NULL) pr_set_param(params, key, s);
else pr_set_param(params, s, s);
}
free(qs);

return params;
Expand Down
10 changes: 10 additions & 0 deletions spec/query_string_parser_spec.rb
Expand Up @@ -163,4 +163,14 @@
h['feed_id'][0].should == '2e2b55b3058696ccbe633e7241d53b16'
h['feed_id'][1].should == '0381dd0545852d28d82ad7d0befbfd92'
end

context 'improper escaping' do
it 'handles ? and = in query params' do
h = qs_parse('appkey=Test&id=http://xkcd.com/530?utm=a&bar=baz')
h.keys.length.should == 3
h['appkey'].should == 'Test'
h['id'].should == 'http://xkcd.com/530?utm=a'
h['bar'].should == 'baz'
end
end
end

0 comments on commit a5f6361

Please sign in to comment.