uri-query_params 0.7.0 → 0.7.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/.gitignore +1 -0
- data/.travis.yml +6 -0
- data/ChangeLog.md +10 -0
- data/Gemfile +17 -0
- data/LICENSE.txt +1 -1
- data/README.md +5 -3
- data/Rakefile +12 -20
- data/gemspec.yml +2 -3
- data/lib/uri/query_params/extensions/uri/generic.rb +38 -19
- data/lib/uri/query_params/mixin.rb +1 -1
- data/lib/uri/query_params/query_params.rb +33 -12
- data/lib/uri/query_params/version.rb +1 -1
- data/spec/query_params_mixin_examples.rb +42 -27
- data/spec/query_params_spec.rb +18 -18
- data/spec/spec_helper.rb +0 -1
- metadata +11 -17
- data/.gemtest +0 -0
data/.gitignore
CHANGED
data/ChangeLog.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
### 0.7.1 / 2015-06-11
|
2
|
+
|
3
|
+
* Fixed a Ruby 2.2 specific bug where `alias`es are defined before the method
|
4
|
+
they alias. (@iraupph)
|
5
|
+
* Removed the `URI::Generic#path_query` monkeypatch.
|
6
|
+
* Override {URI::Generic#to_s} to call the `query` method overrode by
|
7
|
+
{URI::QueryParams::Mixin}, instead of `@query`. Starting in Ruby 2.2.0,
|
8
|
+
`path_query` was inlined directly into `URI::Generic#to_s` which broke our
|
9
|
+
`path_query` monkeypatch.
|
10
|
+
|
1
11
|
### 0.7.0 / 2012-03-27
|
2
12
|
|
3
13
|
* Inject {URI::QueryParams::Mixin} into {URI::Generic}, so all URIs have
|
data/Gemfile
ADDED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# URI query_params
|
2
2
|
|
3
|
-
* [Source](
|
4
|
-
* [Issues](
|
3
|
+
* [Source](https://github.com/postmodern/uri-query_params)
|
4
|
+
* [Issues](https://github.com/postmodern/uri-query_params/issues)
|
5
5
|
* [Documentation](http://rubydoc.info/gems/uri-query_params/frames)
|
6
6
|
* [Email](mailto:postmodern.mod3 at gmail.com)
|
7
7
|
|
8
|
+
[](https://travis-ci.org/postmodern/uri-query_params)
|
9
|
+
|
8
10
|
## Description
|
9
11
|
|
10
12
|
Allows access to the query component of the URI as a Hash. This is similar
|
@@ -41,6 +43,6 @@ Parsing URI query_params embedded within the Fragment Identifier:
|
|
41
43
|
|
42
44
|
## License
|
43
45
|
|
44
|
-
Copyright (c) 2010-
|
46
|
+
Copyright (c) 2010-2015 Hal Brodigan
|
45
47
|
|
46
48
|
See {file:LICENSE.txt} for license information.
|
data/Rakefile
CHANGED
@@ -1,26 +1,18 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
|
4
1
|
begin
|
5
|
-
|
6
|
-
require 'rspec/core/rake_task'
|
7
|
-
|
8
|
-
RSpec::Core::RakeTask.new
|
2
|
+
require 'bundler/setup'
|
9
3
|
rescue LoadError => e
|
10
|
-
|
11
|
-
abort "Please run `gem install rspec` to install RSpec."
|
12
|
-
end
|
4
|
+
abort e.message
|
13
5
|
end
|
6
|
+
|
7
|
+
require 'rake'
|
8
|
+
|
9
|
+
require 'rubygems/tasks'
|
10
|
+
Gem::Tasks.new
|
11
|
+
|
12
|
+
require 'rspec/core/rake_task'
|
13
|
+
RSpec::Core::RakeTask.new
|
14
14
|
task :test => :spec
|
15
15
|
task :default => :spec
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
require 'yard'
|
20
|
-
|
21
|
-
YARD::Rake::YardocTask.new
|
22
|
-
rescue LoadError => e
|
23
|
-
task :yard do
|
24
|
-
abort "Please run `gem install yard` to install YARD."
|
25
|
-
end
|
26
|
-
end
|
17
|
+
require 'yard'
|
18
|
+
YARD::Rake::YardocTask.new
|
data/gemspec.yml
CHANGED
@@ -2,11 +2,10 @@ name: uri-query_params
|
|
2
2
|
summary: Access the query parameters of a URI, just like $_GET in PHP.
|
3
3
|
description: Allows access to the query component of the URI as a Hash.
|
4
4
|
license: MIT
|
5
|
-
homepage:
|
5
|
+
homepage: https://github.com/postmodern/uri-query_params
|
6
6
|
authors: Postmodern
|
7
7
|
email: postmodern.mod3@gmail.com
|
8
8
|
has_yard: true
|
9
9
|
|
10
10
|
development_dependencies:
|
11
|
-
|
12
|
-
yard: ~> 0.6
|
11
|
+
bundler: ~> 1.0
|
@@ -7,32 +7,51 @@ module URI
|
|
7
7
|
|
8
8
|
include URI::QueryParams::Mixin
|
9
9
|
|
10
|
-
private
|
11
|
-
|
12
|
-
alias raw_path_query path_query
|
13
|
-
|
14
10
|
#
|
15
|
-
#
|
16
|
-
# query_params with the parsed parameters.
|
11
|
+
# Constructs String from URI
|
17
12
|
#
|
18
|
-
# @
|
13
|
+
# @note
|
14
|
+
# This is the `URI::Generic#to_s` method from Ruby 2.2.0, with the minor
|
15
|
+
# modification of calling the `query` method overrode by
|
16
|
+
# {URI::QueryParams::Mixin}, instead of `@query`.
|
19
17
|
#
|
20
|
-
# @
|
18
|
+
# @see https://github.com/ruby/ruby/blob/v2_2_0/lib/uri/generic.rb#L1338-L1376
|
21
19
|
#
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
20
|
+
def to_s
|
21
|
+
str = ''
|
22
|
+
if @scheme
|
23
|
+
str << @scheme
|
24
|
+
str << ':'.freeze
|
25
|
+
end
|
29
26
|
|
30
|
-
|
27
|
+
if @opaque
|
28
|
+
str << @opaque
|
31
29
|
else
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
if @host
|
31
|
+
str << '//'.freeze
|
32
|
+
end
|
33
|
+
if self.userinfo
|
34
|
+
str << self.userinfo
|
35
|
+
str << '@'.freeze
|
36
|
+
end
|
37
|
+
if @host
|
38
|
+
str << @host
|
39
|
+
end
|
40
|
+
if @port && @port != self.default_port
|
41
|
+
str << ':'.freeze
|
42
|
+
str << @port.to_s
|
43
|
+
end
|
44
|
+
str << @path
|
45
|
+
if query
|
46
|
+
str << '?'.freeze
|
47
|
+
str << query
|
48
|
+
end
|
49
|
+
end
|
50
|
+
if @fragment
|
51
|
+
str << '#'.freeze
|
52
|
+
str << @fragment
|
35
53
|
end
|
54
|
+
str
|
36
55
|
end
|
37
56
|
|
38
57
|
end
|
@@ -39,7 +39,9 @@ module URI
|
|
39
39
|
# Version 0.6.0 allows {parse} to yield the query params, in the order
|
40
40
|
# they are parsed.
|
41
41
|
#
|
42
|
-
|
42
|
+
# @api semipublic
|
43
|
+
#
|
44
|
+
def self.parse(query_string)
|
43
45
|
query_params = {}
|
44
46
|
|
45
47
|
if query_string
|
@@ -62,6 +64,32 @@ module URI
|
|
62
64
|
return query_params
|
63
65
|
end
|
64
66
|
|
67
|
+
#
|
68
|
+
# Escapes a URI query param value.
|
69
|
+
#
|
70
|
+
# @param [Array, true, false, nil, #to_s] value
|
71
|
+
# The query param value to escape.
|
72
|
+
#
|
73
|
+
# @return [String]
|
74
|
+
# The raw escaped query param value.
|
75
|
+
#
|
76
|
+
# @since 0.7.1
|
77
|
+
#
|
78
|
+
# @api semipublic
|
79
|
+
#
|
80
|
+
def self.escape(value)
|
81
|
+
case value
|
82
|
+
when Array
|
83
|
+
URI.escape(value.join(' '),UNSAFE)
|
84
|
+
when true
|
85
|
+
'active'
|
86
|
+
when false, nil
|
87
|
+
''
|
88
|
+
else
|
89
|
+
URI.escape(value.to_s,UNSAFE)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
65
93
|
#
|
66
94
|
# Dumps the URI query params.
|
67
95
|
#
|
@@ -85,23 +113,16 @@ module URI
|
|
85
113
|
#
|
86
114
|
# @since 0.5.0
|
87
115
|
#
|
88
|
-
|
116
|
+
# @api semipublic
|
117
|
+
#
|
118
|
+
def self.dump(query_params)
|
89
119
|
query = []
|
90
120
|
|
91
121
|
# explicitly re-order the Hash on Ruby 1.8.x
|
92
122
|
query_params.rehash if RUBY_VERSION < '1.9'
|
93
123
|
|
94
124
|
query_params.each do |name,value|
|
95
|
-
value =
|
96
|
-
when Array
|
97
|
-
URI.escape(value.join(' '),UNSAFE)
|
98
|
-
when true
|
99
|
-
'active'
|
100
|
-
when false, nil
|
101
|
-
''
|
102
|
-
else
|
103
|
-
URI.escape(value.to_s,UNSAFE)
|
104
|
-
end
|
125
|
+
value = escape(value)
|
105
126
|
|
106
127
|
query << "#{name}=#{value}"
|
107
128
|
end
|
@@ -10,62 +10,77 @@ shared_examples_for "URI::QueryParams::Mixin" do
|
|
10
10
|
|
11
11
|
before(:each) { uri.query = query }
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
context "when included" do
|
14
|
+
it "should include QueryParams::Mixin" do
|
15
|
+
expect(subject.class).to include(URI::QueryParams::Mixin)
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
it "should still provide access to #query" do
|
19
|
+
expect(uri.query).to eq(query)
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
it "should provide #query_params" do
|
23
|
+
is_expected.to respond_to(:query_params)
|
24
|
+
end
|
23
25
|
end
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
27
|
+
context "when copied" do
|
28
|
+
it "should deep-copy the query_params Hash" do
|
29
|
+
original = subject.query_params.object_id
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
expect(subject.dup.query_params.object_id).not_to eq(original)
|
32
|
+
expect(subject.clone.query_params.object_id).not_to eq(original)
|
33
|
+
end
|
33
34
|
end
|
34
35
|
|
35
|
-
|
36
|
-
|
36
|
+
describe "#query=" do
|
37
|
+
it "should update #query_params after #query is set" do
|
38
|
+
subject.query = 'u=2'
|
37
39
|
|
38
|
-
|
40
|
+
expect(subject.query_params['u']).to eq('2')
|
41
|
+
end
|
39
42
|
end
|
40
43
|
|
41
|
-
|
42
|
-
|
44
|
+
describe "#query" do
|
45
|
+
it "should dump out the #query_params when accessing #query" do
|
46
|
+
subject.query_params = {'u' => '3'}
|
47
|
+
expect(subject.query).to eq('u=3')
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should properly escape query param values" do
|
51
|
+
subject.query_params = {'x' => '1&2', 'y' => 'one=two', 'z' => '?'}
|
43
52
|
|
44
|
-
|
45
|
-
|
53
|
+
expect(subject.query).to eq("x=1%262&y=one%3Dtwo&z=%3F")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#to_s" do
|
58
|
+
it "should include the #query_params" do
|
59
|
+
expect(subject.to_s.split('?',2).last).to eq(query)
|
60
|
+
end
|
46
61
|
end
|
47
62
|
|
48
63
|
describe "#query_params" do
|
49
64
|
subject { uri.query_params }
|
50
65
|
|
51
66
|
it "should be a Hash" do
|
52
|
-
subject.class.
|
67
|
+
expect(subject.class).to eq(Hash)
|
53
68
|
end
|
54
69
|
|
55
70
|
it "should contain params" do
|
56
|
-
|
71
|
+
is_expected.not_to be_empty
|
57
72
|
end
|
58
73
|
|
59
74
|
it "can contain single-word params" do
|
60
|
-
subject['x'].
|
75
|
+
expect(subject['x']).to eq('1')
|
61
76
|
end
|
62
77
|
|
63
78
|
it "can contain multi-word params" do
|
64
|
-
subject['y'].
|
79
|
+
expect(subject['y']).to eq('one two')
|
65
80
|
end
|
66
81
|
|
67
82
|
it "can contain empty params" do
|
68
|
-
subject['z'].
|
83
|
+
expect(subject['z']).to be_empty
|
69
84
|
end
|
70
85
|
end
|
71
86
|
end
|
data/spec/query_params_spec.rb
CHANGED
@@ -6,41 +6,41 @@ require 'uri'
|
|
6
6
|
describe URI::QueryParams do
|
7
7
|
describe "parse" do
|
8
8
|
it "should not parse an empty String" do
|
9
|
-
subject.parse('').
|
9
|
+
expect(subject.parse('')).to be_empty
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should not parse empty params" do
|
13
|
-
subject.parse('a&&&b').
|
13
|
+
expect(subject.parse('a&&&b')).to eq({'a' => '', 'b' => ''})
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should parse a single query param name" do
|
17
|
-
subject.parse('x').
|
17
|
+
expect(subject.parse('x')).to have_key('x')
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should parse a query param with an empty value" do
|
21
21
|
query_params = subject.parse('x=')
|
22
22
|
|
23
|
-
query_params.
|
24
|
-
query_params['x'].
|
23
|
+
expect(query_params).to have_key('x')
|
24
|
+
expect(query_params['x']).to be_empty
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should URI decode query param values" do
|
28
28
|
query_params = subject.parse('x=1%202')
|
29
29
|
|
30
|
-
query_params['x'].
|
30
|
+
expect(query_params['x']).to eq('1 2')
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should ignore multiple '=' characters in query param values" do
|
34
34
|
query_params = subject.parse('x=1=2')
|
35
35
|
|
36
|
-
query_params['x'].
|
36
|
+
expect(query_params['x']).to eq('1=2')
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should parse multiple query params" do
|
40
40
|
query_params = subject.parse('x=1&y=2')
|
41
41
|
|
42
|
-
query_params['x'].
|
43
|
-
query_params['y'].
|
42
|
+
expect(query_params['x']).to eq('1')
|
43
|
+
expect(query_params['y']).to eq('2')
|
44
44
|
end
|
45
45
|
|
46
46
|
context "when given a block" do
|
@@ -51,7 +51,7 @@ describe URI::QueryParams do
|
|
51
51
|
params << [name, value]
|
52
52
|
end
|
53
53
|
|
54
|
-
params.
|
54
|
+
expect(params).to eq([['z', '1'], ['z', '2'], ['z', '3']])
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should yield the query params in the order they are parsed" do
|
@@ -61,38 +61,38 @@ describe URI::QueryParams do
|
|
61
61
|
params << [name, value]
|
62
62
|
end
|
63
63
|
|
64
|
-
params.
|
64
|
+
expect(params).to eq([['z', '1'], ['y', '2'], ['x', '3']])
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
69
|
describe "dump" do
|
70
70
|
it "should not dump an empty Hash" do
|
71
|
-
subject.dump({}).
|
71
|
+
expect(subject.dump({})).to be_empty
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should dump query params with no values" do
|
75
|
-
subject.dump({'x' => nil}).
|
75
|
+
expect(subject.dump({'x' => nil})).to eq('x=')
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should dump query params with empty values" do
|
79
|
-
subject.dump({'x' => ''}).
|
79
|
+
expect(subject.dump({'x' => ''})).to eq('x=')
|
80
80
|
end
|
81
81
|
|
82
82
|
it "should dump query params with true values" do
|
83
|
-
subject.dump({'x' => true}).
|
83
|
+
expect(subject.dump({'x' => true})).to eq('x=active')
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should dump query params with non String values" do
|
87
|
-
subject.dump({'x' => 1}).
|
87
|
+
expect(subject.dump({'x' => 1})).to eq('x=1')
|
88
88
|
end
|
89
89
|
|
90
90
|
it "should dump query params with Array values" do
|
91
|
-
subject.dump({'x' => [1,2]}).
|
91
|
+
expect(subject.dump({'x' => [1,2]})).to eq('x=1%202')
|
92
92
|
end
|
93
93
|
|
94
94
|
it "should dump multiple query params" do
|
95
|
-
subject.dump({'x' => '1', 'y' => '2'}).
|
95
|
+
expect(subject.dump({'x' => '1', 'y' => '2'})).to eq('x=1&y=2')
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uri-query_params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,30 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-06-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement:
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
21
|
+
version: '1.0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: yard
|
27
|
-
requirement: &13944020 !ruby/object:Gem::Requirement
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
25
|
none: false
|
29
26
|
requirements:
|
30
27
|
- - ~>
|
31
28
|
- !ruby/object:Gem::Version
|
32
|
-
version: '0
|
33
|
-
type: :development
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *13944020
|
29
|
+
version: '1.0'
|
36
30
|
description: Allows access to the query component of the URI as a Hash.
|
37
31
|
email: postmodern.mod3@gmail.com
|
38
32
|
executables: []
|
@@ -40,11 +34,12 @@ extensions: []
|
|
40
34
|
extra_rdoc_files: []
|
41
35
|
files:
|
42
36
|
- .document
|
43
|
-
- .gemtest
|
44
37
|
- .gitignore
|
45
38
|
- .rspec
|
39
|
+
- .travis.yml
|
46
40
|
- .yardopts
|
47
41
|
- ChangeLog.md
|
42
|
+
- Gemfile
|
48
43
|
- LICENSE.txt
|
49
44
|
- README.md
|
50
45
|
- Rakefile
|
@@ -64,7 +59,7 @@ files:
|
|
64
59
|
- spec/query_params_spec.rb
|
65
60
|
- spec/spec_helper.rb
|
66
61
|
- uri-query_params.gemspec
|
67
|
-
homepage:
|
62
|
+
homepage: https://github.com/postmodern/uri-query_params
|
68
63
|
licenses:
|
69
64
|
- MIT
|
70
65
|
post_install_message:
|
@@ -85,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
80
|
version: '0'
|
86
81
|
requirements: []
|
87
82
|
rubyforge_project:
|
88
|
-
rubygems_version: 1.8.
|
83
|
+
rubygems_version: 1.8.23.2
|
89
84
|
signing_key:
|
90
85
|
specification_version: 3
|
91
86
|
summary: Access the query parameters of a URI, just like $_GET in PHP.
|
@@ -94,4 +89,3 @@ test_files:
|
|
94
89
|
- spec/extensions/uri/generic_spec.rb
|
95
90
|
- spec/extensions/uri/http_spec.rb
|
96
91
|
- spec/query_params_spec.rb
|
97
|
-
has_rdoc:
|
data/.gemtest
DELETED
File without changes
|