uri-query_params 0.6.0 → 0.7.2
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.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +31 -0
- data/.gitignore +6 -5
- data/ChangeLog.md +32 -1
- data/Gemfile +17 -0
- data/LICENSE.txt +1 -1
- data/README.md +11 -5
- data/Rakefile +6 -30
- data/gemspec.yml +2 -4
- data/lib/uri/query_params/extensions.rb +2 -2
- data/lib/uri/query_params/extensions/addressable/uri.rb +11 -0
- data/lib/uri/query_params/extensions/uri.rb +1 -0
- data/lib/uri/query_params/extensions/uri/generic.rb +58 -0
- data/lib/uri/query_params/mixin.rb +54 -59
- data/lib/uri/query_params/query_params.rb +40 -15
- data/lib/uri/query_params/version.rb +1 -1
- data/spec/extensions/addressable/uri_spec.rb +9 -0
- data/spec/extensions/uri/generic_spec.rb +9 -0
- data/spec/extensions/{http_spec.rb → uri/http_spec.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 +30 -49
- data/.gemtest +0 -0
- data/lib/uri/query_params/extensions/http.rb +0 -11
- data/lib/uri/query_params/extensions/https.rb +0 -3
- data/spec/extensions/https_spec.rb +0 -9
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 98c8b432e06a2809b54dfa91b64fbfe6424b7fa8db77cc6193b577b40eca90a5
|
4
|
+
data.tar.gz: af5598c46102cc70eda79bea50ad934532e14fa77729280fdd5dd0e9da2f13c6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 57dca3b3b845dfaf78873bae42784b957a3efb21c684fd4d6ffff615bcb96f0ab554491167dbf7c2424321c263af7fe5b5ac52c753c0c4b8d94a0ef7ebe6412f
|
7
|
+
data.tar.gz: ad0079b30c44014d25f08c5af69d08bc1eb7d33be6a9cbaa7afec6e8f31df9ade45d852be58abdbb13f94409ac30ea1c8abbee383e13d4c205e13a878dabd26c
|
@@ -0,0 +1,31 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: ['**']
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
tests:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
fail-fast: false
|
14
|
+
matrix:
|
15
|
+
ruby:
|
16
|
+
- 2.4
|
17
|
+
- 2.5
|
18
|
+
- 2.6
|
19
|
+
- 2.7
|
20
|
+
- jruby
|
21
|
+
name: Ruby ${{ matrix.ruby }}
|
22
|
+
steps:
|
23
|
+
- uses: actions/checkout@v2
|
24
|
+
- name: Set up Ruby
|
25
|
+
uses: ruby/setup-ruby@v1
|
26
|
+
with:
|
27
|
+
ruby-version: ${{ matrix.ruby }}
|
28
|
+
- name: Install dependencies
|
29
|
+
run: bundle install --jobs 4 --retry 3
|
30
|
+
- name: Run tests
|
31
|
+
run: bundle exec rake test
|
data/.gitignore
CHANGED
data/ChangeLog.md
CHANGED
@@ -1,3 +1,34 @@
|
|
1
|
+
### 0.7.2 / 2020-11-29
|
2
|
+
|
3
|
+
* Use `URI::DEFAULT_PARSER.escape` / `.unescape` instead of the deprecated
|
4
|
+
`URI.escape` / `URI.unescape`.
|
5
|
+
|
6
|
+
### 0.7.1 / 2015-06-11
|
7
|
+
|
8
|
+
* Fixed a Ruby 2.2 specific bug where `alias`es are defined before the method
|
9
|
+
they alias. (@iraupph)
|
10
|
+
* Removed the `URI::Generic#path_query` monkeypatch.
|
11
|
+
* Override {URI::Generic#to_s} to call the `query` method overrode by
|
12
|
+
{URI::QueryParams::Mixin}, instead of `@query`. Starting in Ruby 2.2.0,
|
13
|
+
`path_query` was inlined directly into `URI::Generic#to_s` which broke our
|
14
|
+
`path_query` monkeypatch.
|
15
|
+
|
16
|
+
### 0.7.0 / 2012-03-27
|
17
|
+
|
18
|
+
* Inject {URI::QueryParams::Mixin} into {URI::Generic}, so all URIs have
|
19
|
+
`query_params`.
|
20
|
+
* Inject {URI::QueryParams::Mixin} into `Addressable::URI`, if `addressable/uri`
|
21
|
+
is loaded.
|
22
|
+
|
23
|
+
### 0.6.2 / 2012-03-15
|
24
|
+
|
25
|
+
* Fixed a query parameter ordering issue in {URI::QueryParams.dump},
|
26
|
+
under Ruby 1.8.x.
|
27
|
+
|
28
|
+
### 0.6.1 / 2011-12-31
|
29
|
+
|
30
|
+
* Added white-space and unprintable characters to {URI::QueryParams::UNSAFE}.
|
31
|
+
|
1
32
|
### 0.6.0 / 2011-12-06
|
2
33
|
|
3
34
|
* Allow {URI::QueryParams.parse} to yield query-params, in the order they were
|
@@ -17,7 +48,7 @@
|
|
17
48
|
* Contains RFC 3986 unsafe URI characters.
|
18
49
|
* Use {URI::QueryParams::UNSAFE} in {URI::QueryParams.dump} for safer
|
19
50
|
query strings.
|
20
|
-
* Added
|
51
|
+
* Added `URI::QueryParams::Mixin#query`:
|
21
52
|
* If any query-params are set, dump them out using
|
22
53
|
{URI::QueryParams.dump}.
|
23
54
|
* Renamed `parse_query_params` to
|
data/Gemfile
ADDED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
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
8
|
## Description
|
9
9
|
|
10
10
|
Allows access to the query component of the URI as a Hash. This is similar
|
11
|
-
to `$_GET` from PHP, except available on any
|
11
|
+
to `$_GET` from PHP, except available on any Ruby URI object.
|
12
12
|
|
13
13
|
## Examples
|
14
14
|
|
@@ -29,12 +29,18 @@ Setting the URI query_params:
|
|
29
29
|
url.to_s
|
30
30
|
# => "http://www.google.com/search?btnG=Search&hs=1HY&rls=org.mozilla:en-US:official&client=firefox-a&hl=en&q=Upright%20Citizens%20Brigade"
|
31
31
|
|
32
|
+
Parsing URI query_params embedded within the Fragment Identifier:
|
33
|
+
|
34
|
+
url = URI('https://twitter.com/#!/download?lang=en&logged_out=1')
|
35
|
+
URI(url.fragment).query_params
|
36
|
+
# => {"logged_out"=>"1", "lang"=>"en"}
|
37
|
+
|
32
38
|
## Install
|
33
39
|
|
34
|
-
$
|
40
|
+
$ gem install uri-query_params
|
35
41
|
|
36
42
|
## License
|
37
43
|
|
38
|
-
Copyright (c) 2010-
|
44
|
+
Copyright (c) 2010-2020 Hal Brodigan
|
39
45
|
|
40
46
|
See {file:LICENSE.txt} for license information.
|
data/Rakefile
CHANGED
@@ -1,36 +1,12 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'rake'
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
require 'ore/tasks'
|
3
|
+
require 'rubygems/tasks'
|
4
|
+
Gem::Tasks.new
|
7
5
|
|
8
|
-
|
9
|
-
|
10
|
-
warn e.message
|
11
|
-
warn "Run `gem install ore-tasks` to install 'ore/tasks'."
|
12
|
-
end
|
13
|
-
|
14
|
-
begin
|
15
|
-
gem 'rspec', '~> 2.4'
|
16
|
-
require 'rspec/core/rake_task'
|
17
|
-
|
18
|
-
RSpec::Core::RakeTask.new
|
19
|
-
rescue LoadError => e
|
20
|
-
task :spec do
|
21
|
-
abort "Please run `gem install rspec` to install RSpec."
|
22
|
-
end
|
23
|
-
end
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
RSpec::Core::RakeTask.new
|
24
8
|
task :test => :spec
|
25
9
|
task :default => :spec
|
26
10
|
|
27
|
-
|
28
|
-
|
29
|
-
require 'yard'
|
30
|
-
|
31
|
-
YARD::Rake::YardocTask.new
|
32
|
-
rescue LoadError => e
|
33
|
-
task :yard do
|
34
|
-
abort "Please run `gem install yard` to install YARD."
|
35
|
-
end
|
36
|
-
end
|
11
|
+
require 'yard'
|
12
|
+
YARD::Rake::YardocTask.new
|
data/gemspec.yml
CHANGED
@@ -2,12 +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
|
-
rspec: ~> 2.4
|
13
|
-
yard: ~> 0.6.0
|
11
|
+
bundler: ~> 2.0
|
@@ -1,2 +1,2 @@
|
|
1
|
-
require 'uri/query_params/extensions/
|
2
|
-
require 'uri/query_params/extensions/
|
1
|
+
require 'uri/query_params/extensions/uri'
|
2
|
+
require 'uri/query_params/extensions/addressable/uri' if defined?(Addressable)
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'uri/query_params/extensions/uri/generic'
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'uri/query_params/mixin'
|
2
|
+
|
3
|
+
require 'uri/generic'
|
4
|
+
|
5
|
+
module URI
|
6
|
+
class Generic
|
7
|
+
|
8
|
+
include URI::QueryParams::Mixin
|
9
|
+
|
10
|
+
#
|
11
|
+
# Constructs String from URI
|
12
|
+
#
|
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`.
|
17
|
+
#
|
18
|
+
# @see https://github.com/ruby/ruby/blob/v2_2_0/lib/uri/generic.rb#L1338-L1376
|
19
|
+
#
|
20
|
+
def to_s
|
21
|
+
str = ''
|
22
|
+
if @scheme
|
23
|
+
str << @scheme
|
24
|
+
str << ':'.freeze
|
25
|
+
end
|
26
|
+
|
27
|
+
if @opaque
|
28
|
+
str << @opaque
|
29
|
+
else
|
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
|
53
|
+
end
|
54
|
+
str
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -10,6 +10,58 @@ module URI
|
|
10
10
|
# Allows setting the query_params.
|
11
11
|
attr_writer :query_params
|
12
12
|
|
13
|
+
#
|
14
|
+
# Called when {Mixin} is included into a URI Class. Overrides the `query`
|
15
|
+
# and `query=` methods to transparently update the {#query_params}.
|
16
|
+
#
|
17
|
+
def self.included(base)
|
18
|
+
base.module_eval do
|
19
|
+
alias raw_query query
|
20
|
+
|
21
|
+
#
|
22
|
+
# The raw query-string.
|
23
|
+
#
|
24
|
+
# @return [String, nil]
|
25
|
+
# The raw query-string.
|
26
|
+
#
|
27
|
+
# @see QueryParams.dump
|
28
|
+
#
|
29
|
+
# @since 0.5.2
|
30
|
+
#
|
31
|
+
def query
|
32
|
+
if @query_params
|
33
|
+
URI::QueryParams.dump(@query_params)
|
34
|
+
else
|
35
|
+
raw_query
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
alias raw_query= query=
|
40
|
+
|
41
|
+
#
|
42
|
+
# Sets the query string and updates query_params.
|
43
|
+
#
|
44
|
+
# @param [String] query_str
|
45
|
+
# The new URI query string to use.
|
46
|
+
#
|
47
|
+
# @return [String]
|
48
|
+
# The new URI query string.
|
49
|
+
#
|
50
|
+
# @example
|
51
|
+
# url.query = 'a=1&b=2'
|
52
|
+
# # => "a=1&b=2"
|
53
|
+
#
|
54
|
+
# @see QueryParams.parse
|
55
|
+
#
|
56
|
+
def query=(new_query)
|
57
|
+
new_query = (self.raw_query = new_query)
|
58
|
+
|
59
|
+
parse_query_params! if @query_params
|
60
|
+
return new_query
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
13
65
|
#
|
14
66
|
# Deep-copies the {#query_params} from another URL.
|
15
67
|
#
|
@@ -26,46 +78,6 @@ module URI
|
|
26
78
|
super(url)
|
27
79
|
end
|
28
80
|
|
29
|
-
#
|
30
|
-
# The raw query-string.
|
31
|
-
#
|
32
|
-
# @return [String, nil]
|
33
|
-
# The raw query-string.
|
34
|
-
#
|
35
|
-
# @see QueryParams.dump
|
36
|
-
#
|
37
|
-
# @since 0.5.2
|
38
|
-
#
|
39
|
-
def query
|
40
|
-
if @query_params
|
41
|
-
QueryParams.dump(@query_params)
|
42
|
-
else
|
43
|
-
super
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
#
|
48
|
-
# Sets the query string and updates query_params.
|
49
|
-
#
|
50
|
-
# @param [String] query_str
|
51
|
-
# The new URI query string to use.
|
52
|
-
#
|
53
|
-
# @return [String]
|
54
|
-
# The new URI query string.
|
55
|
-
#
|
56
|
-
# @example
|
57
|
-
# url.query = 'a=1&b=2'
|
58
|
-
# # => "a=1&b=2"
|
59
|
-
#
|
60
|
-
# @see QueryParams.parse
|
61
|
-
#
|
62
|
-
def query=(raw_query)
|
63
|
-
new_query = super(raw_query)
|
64
|
-
|
65
|
-
parse_query_params! if @query_params
|
66
|
-
return new_query
|
67
|
-
end
|
68
|
-
|
69
81
|
#
|
70
82
|
# The query params of the URI.
|
71
83
|
#
|
@@ -100,7 +112,7 @@ module URI
|
|
100
112
|
query_params.each(&block)
|
101
113
|
end
|
102
114
|
|
103
|
-
|
115
|
+
private
|
104
116
|
|
105
117
|
#
|
106
118
|
# Parses the query parameters from the query data, populating
|
@@ -111,26 +123,9 @@ module URI
|
|
111
123
|
# @since 0.5.2
|
112
124
|
#
|
113
125
|
def parse_query_params!
|
114
|
-
@query_params = QueryParams.parse(@query)
|
126
|
+
@query_params = URI::QueryParams.parse(@query)
|
115
127
|
end
|
116
128
|
|
117
|
-
private
|
118
|
-
|
119
|
-
def path_query
|
120
|
-
if @query_params
|
121
|
-
str = @path
|
122
|
-
|
123
|
-
unless @query_params.empty?
|
124
|
-
str += '?' + QueryParams.dump(@query_params)
|
125
|
-
end
|
126
|
-
|
127
|
-
str
|
128
|
-
else
|
129
|
-
# do not rebuild the path-query, if the query_params have not
|
130
|
-
# been parsed yet
|
131
|
-
super
|
132
|
-
end
|
133
|
-
end
|
134
129
|
end
|
135
130
|
end
|
136
131
|
end
|
@@ -4,8 +4,9 @@ module URI
|
|
4
4
|
module QueryParams
|
5
5
|
# RFC 3986 unsafe characters (including ' ')
|
6
6
|
UNSAFE = [
|
7
|
-
'
|
8
|
-
'/', '?', '%', '#', '[', ']'
|
7
|
+
'!', '*', "'", '(', ')', ';', ':', '@', '&', '=', '+', '$', ',',
|
8
|
+
'/', '?', '%', '#', '[', ']', ' ', "\f", "\n", "\r", "\t", "\v",
|
9
|
+
"\x7f", *("\x00".."\x1f")
|
9
10
|
].join
|
10
11
|
|
11
12
|
#
|
@@ -38,7 +39,9 @@ module URI
|
|
38
39
|
# Version 0.6.0 allows {parse} to yield the query params, in the order
|
39
40
|
# they are parsed.
|
40
41
|
#
|
41
|
-
|
42
|
+
# @api semipublic
|
43
|
+
#
|
44
|
+
def self.parse(query_string)
|
42
45
|
query_params = {}
|
43
46
|
|
44
47
|
if query_string
|
@@ -48,7 +51,7 @@ module URI
|
|
48
51
|
|
49
52
|
name, value = param.split('=',2)
|
50
53
|
value = if value
|
51
|
-
URI.unescape(value)
|
54
|
+
URI::DEFAULT_PARSER.unescape(value)
|
52
55
|
else
|
53
56
|
''
|
54
57
|
end
|
@@ -61,6 +64,32 @@ module URI
|
|
61
64
|
return query_params
|
62
65
|
end
|
63
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::DEFAULT_PARSER.escape(value.join(' '),UNSAFE)
|
84
|
+
when true
|
85
|
+
'active'
|
86
|
+
when false, nil
|
87
|
+
''
|
88
|
+
else
|
89
|
+
URI::DEFAULT_PARSER.escape(value.to_s,UNSAFE)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
64
93
|
#
|
65
94
|
# Dumps the URI query params.
|
66
95
|
#
|
@@ -84,20 +113,16 @@ module URI
|
|
84
113
|
#
|
85
114
|
# @since 0.5.0
|
86
115
|
#
|
87
|
-
|
116
|
+
# @api semipublic
|
117
|
+
#
|
118
|
+
def self.dump(query_params)
|
88
119
|
query = []
|
89
120
|
|
121
|
+
# explicitly re-order the Hash on Ruby 1.8.x
|
122
|
+
query_params.rehash if RUBY_VERSION < '1.9'
|
123
|
+
|
90
124
|
query_params.each do |name,value|
|
91
|
-
value =
|
92
|
-
when Array
|
93
|
-
URI.escape(value.join(' '),UNSAFE)
|
94
|
-
when true
|
95
|
-
'active'
|
96
|
-
when false, nil
|
97
|
-
''
|
98
|
-
else
|
99
|
-
URI.escape(value.to_s,UNSAFE)
|
100
|
-
end
|
125
|
+
value = escape(value)
|
101
126
|
|
102
127
|
query << "#{name}=#{value}"
|
103
128
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'query_params_mixin_examples'
|
3
|
+
require 'uri/query_params/extensions/addressable/uri'
|
4
|
+
|
5
|
+
describe Addressable::URI do
|
6
|
+
let(:uri) { described_class.parse('http://www.example.com/page.php') }
|
7
|
+
|
8
|
+
it_should_behave_like "URI::QueryParams::Mixin"
|
9
|
+
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,105 +1,86 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uri-query_params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.7.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Postmodern
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2020-11-29 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
16
|
-
requirement:
|
17
|
-
none: false
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '0
|
19
|
+
version: '2.0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: rspec
|
27
|
-
requirement: &18099820 !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
|
-
requirements:
|
30
|
-
- - ~>
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '2.4'
|
33
|
-
type: :development
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *18099820
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: yard
|
38
|
-
requirement: &18099340 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
23
|
requirements:
|
41
|
-
- - ~>
|
24
|
+
- - "~>"
|
42
25
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
44
|
-
type: :development
|
45
|
-
prerelease: false
|
46
|
-
version_requirements: *18099340
|
26
|
+
version: '2.0'
|
47
27
|
description: Allows access to the query component of the URI as a Hash.
|
48
28
|
email: postmodern.mod3@gmail.com
|
49
29
|
executables: []
|
50
30
|
extensions: []
|
51
31
|
extra_rdoc_files: []
|
52
32
|
files:
|
53
|
-
- .document
|
54
|
-
- .
|
55
|
-
- .gitignore
|
56
|
-
- .rspec
|
57
|
-
- .yardopts
|
33
|
+
- ".document"
|
34
|
+
- ".github/workflows/ruby.yml"
|
35
|
+
- ".gitignore"
|
36
|
+
- ".rspec"
|
37
|
+
- ".yardopts"
|
58
38
|
- ChangeLog.md
|
39
|
+
- Gemfile
|
59
40
|
- LICENSE.txt
|
60
41
|
- README.md
|
61
42
|
- Rakefile
|
62
43
|
- gemspec.yml
|
63
44
|
- lib/uri/query_params.rb
|
64
45
|
- lib/uri/query_params/extensions.rb
|
65
|
-
- lib/uri/query_params/extensions/
|
66
|
-
- lib/uri/query_params/extensions/
|
46
|
+
- lib/uri/query_params/extensions/addressable/uri.rb
|
47
|
+
- lib/uri/query_params/extensions/uri.rb
|
48
|
+
- lib/uri/query_params/extensions/uri/generic.rb
|
67
49
|
- lib/uri/query_params/mixin.rb
|
68
50
|
- lib/uri/query_params/query_params.rb
|
69
51
|
- lib/uri/query_params/version.rb
|
70
|
-
- spec/extensions/
|
71
|
-
- spec/extensions/
|
52
|
+
- spec/extensions/addressable/uri_spec.rb
|
53
|
+
- spec/extensions/uri/generic_spec.rb
|
54
|
+
- spec/extensions/uri/http_spec.rb
|
72
55
|
- spec/query_params_mixin_examples.rb
|
73
56
|
- spec/query_params_spec.rb
|
74
57
|
- spec/spec_helper.rb
|
75
58
|
- uri-query_params.gemspec
|
76
|
-
homepage:
|
59
|
+
homepage: https://github.com/postmodern/uri-query_params
|
77
60
|
licenses:
|
78
61
|
- MIT
|
62
|
+
metadata: {}
|
79
63
|
post_install_message:
|
80
64
|
rdoc_options: []
|
81
65
|
require_paths:
|
82
66
|
- lib
|
83
67
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
-
none: false
|
85
68
|
requirements:
|
86
|
-
- -
|
69
|
+
- - ">="
|
87
70
|
- !ruby/object:Gem::Version
|
88
71
|
version: '0'
|
89
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
73
|
requirements:
|
92
|
-
- -
|
74
|
+
- - ">="
|
93
75
|
- !ruby/object:Gem::Version
|
94
76
|
version: '0'
|
95
77
|
requirements: []
|
96
|
-
|
97
|
-
rubygems_version: 1.8.10
|
78
|
+
rubygems_version: 3.1.4
|
98
79
|
signing_key:
|
99
|
-
specification_version:
|
80
|
+
specification_version: 4
|
100
81
|
summary: Access the query parameters of a URI, just like $_GET in PHP.
|
101
82
|
test_files:
|
102
|
-
- spec/extensions/
|
103
|
-
- spec/extensions/
|
83
|
+
- spec/extensions/addressable/uri_spec.rb
|
84
|
+
- spec/extensions/uri/generic_spec.rb
|
85
|
+
- spec/extensions/uri/http_spec.rb
|
104
86
|
- spec/query_params_spec.rb
|
105
|
-
has_rdoc:
|
data/.gemtest
DELETED
File without changes
|