query_string_parser 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2010, dan sinclair
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ * The name of the author nor the names of any contributors may be used
12
+ to endorse or promote products derived from this software without
13
+ specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17
+ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18
+ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
+ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README ADDED
@@ -0,0 +1,22 @@
1
+ Query String Parser
2
+ ===================
3
+
4
+ We parse a lot of queries at PostRank Inc. The time taken to parse those queries starts to add up.
5
+ Eventually we got to the point where we decided to create a simple C based parser. Hence, QueryStringParser.
6
+
7
+ A more detailed explanation of the origins can be found at: http://everburning.com/news/introducing-querystringparser
8
+
9
+ Usage is pretty simple, you can either call the function against the QueryStringParser module, or include
10
+ the module into your code. There is only one method, qs_parse.
11
+
12
+ require 'query_string_parser'
13
+ QueryStringParser.qs_parse("my=query&string=parser")
14
+ => {"my"=>"query", "string"=>"parser"}
15
+
16
+ include QueryStringParser
17
+ qs_parse("does[]=array&does[]=data&does[3]=values&does=more")
18
+ => {"does"=>["array", "data", "values", "more"]}
19
+
20
+
21
+ Questions, comments, drop me a line. dj2 at everburning dot com
22
+
@@ -93,19 +93,23 @@ pr_query_parser(VALUE self, VALUE query_string, VALUE delim)
93
93
 
94
94
  params = rb_hash_new();
95
95
  qs = strdup(RSTRING_PTR(query_string));
96
- for (s = qs, p = qs, key = qs; *p != 0; p++)
96
+ for (s = qs, p = qs; *p != 0; p++)
97
97
  {
98
98
  if (*p == delimiter)
99
99
  {
100
+ *p = 0;
100
101
  if (key != NULL)
101
102
  {
102
- *p = 0;
103
103
  pr_set_param(params, key, s);
104
+ key = NULL;
105
+ }
106
+ else
107
+ {
108
+ pr_set_param(params, s, s);
104
109
  }
105
110
  s = (p + 1);
106
- key = s;
107
111
  }
108
- else if (*p == '=')
112
+ else if ((*p == '=') && (key == NULL))
109
113
  {
110
114
  *p = 0;
111
115
  key = s;
@@ -113,7 +117,11 @@ pr_query_parser(VALUE self, VALUE query_string, VALUE delim)
113
117
  }
114
118
  }
115
119
 
116
- if (key != NULL) pr_set_param(params, key, s);
120
+ if (s != NULL)
121
+ {
122
+ if (key != NULL) pr_set_param(params, key, s);
123
+ else pr_set_param(params, s, s);
124
+ }
117
125
  free(qs);
118
126
 
119
127
  return params;
@@ -163,4 +163,14 @@ describe 'QueryStringParser' do
163
163
  h['feed_id'][0].should == '2e2b55b3058696ccbe633e7241d53b16'
164
164
  h['feed_id'][1].should == '0381dd0545852d28d82ad7d0befbfd92'
165
165
  end
166
+
167
+ context 'improper escaping' do
168
+ it 'handles ? and = in query params' do
169
+ h = qs_parse('appkey=Test&id=http://xkcd.com/530?utm=a&bar=baz')
170
+ h.keys.length.should == 3
171
+ h['appkey'].should == 'Test'
172
+ h['id'].should == 'http://xkcd.com/530?utm=a'
173
+ h['bar'].should == 'baz'
174
+ end
175
+ end
166
176
  end
metadata CHANGED
@@ -1,12 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: query_string_parser
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 0
9
- version: 0.1.0
4
+ version: 0.1.1
10
5
  platform: ruby
11
6
  authors:
12
7
  - dan sinclair
@@ -14,7 +9,7 @@ autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
11
 
17
- date: 2010-06-15 00:00:00 -04:00
12
+ date: 2010-09-02 00:00:00 -04:00
18
13
  default_executable:
19
14
  dependencies: []
20
15
 
@@ -25,14 +20,17 @@ executables: []
25
20
  extensions:
26
21
  - ext/extconf.rb
27
22
  - ext/extconf.rb
28
- extra_rdoc_files: []
29
-
23
+ extra_rdoc_files:
24
+ - LICENSE
25
+ - README
30
26
  files:
31
27
  - Rakefile
32
28
  - ext/extconf.rb
33
29
  - ext/pr_query_parser.c
34
30
  - lib/query_string_parser.rb
35
31
  - spec/query_string_parser_spec.rb
32
+ - LICENSE
33
+ - README
36
34
  has_rdoc: true
37
35
  homepage: http://github.com/dj2/query_string_parser
38
36
  licenses: []
@@ -46,20 +44,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
46
44
  requirements:
47
45
  - - ">="
48
46
  - !ruby/object:Gem::Version
49
- segments:
50
- - 0
51
47
  version: "0"
48
+ version:
52
49
  required_rubygems_version: !ruby/object:Gem::Requirement
53
50
  requirements:
54
51
  - - ">="
55
52
  - !ruby/object:Gem::Version
56
- segments:
57
- - 0
58
53
  version: "0"
54
+ version:
59
55
  requirements: []
60
56
 
61
57
  rubyforge_project:
62
- rubygems_version: 1.3.6
58
+ rubygems_version: 1.3.5
63
59
  signing_key:
64
60
  specification_version: 3
65
61
  summary: Simple query string parser