uri-query_params 0.6.2 → 0.8.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: da86f32384123e5240b11aae3767b48770696604afb3eee3c4a04351badaa585
4
+ data.tar.gz: c469674aa5d7f20e72f19dd6fb2eac80917182638706390fe1cc2e60d89ecb98
5
+ SHA512:
6
+ metadata.gz: 62031ef7a85c4e0d17205964f3d2b14c0596d42da4c04f583faedd83f8a7f3c861bddfefdae6e4c36055913e2a59738a93021d943bd0447d91cf360d3762b8b3
7
+ data.tar.gz: af4ad8d768e9114636279f4abe2d197b439f856474bab5dbb5269388e8f5ad7aaa0a780858e16c797d77f68874f696d3c2e58e486dfada640bcbe19b826b4e3e
@@ -0,0 +1,28 @@
1
+ name: CI
2
+
3
+ on: [ push, pull_request ]
4
+
5
+ jobs:
6
+ tests:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ ruby:
12
+ - 2.6
13
+ - 2.7
14
+ - '3.0'
15
+ - 3.1
16
+ - jruby
17
+ - truffleruby
18
+ name: Ruby ${{ matrix.ruby }}
19
+ steps:
20
+ - uses: actions/checkout@v2
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ - name: Install dependencies
26
+ run: bundle install --jobs 4 --retry 3
27
+ - name: Run tests
28
+ run: bundle exec rake test
data/.gitignore CHANGED
@@ -1,9 +1,10 @@
1
- doc
2
- pkg
3
- tmp/*
1
+ /Gemfile.lock
2
+ /doc/
3
+ /pkg/
4
+ /vendor/bundle
5
+ /.bundle
6
+ /.yardoc
4
7
  .DS_Store
5
- .bundle
6
- .yardoc
7
8
  *.db
8
9
  *.log
9
10
  *.swp
data/ChangeLog.md CHANGED
@@ -1,3 +1,32 @@
1
+ ### 0.8.0 / 2022-01-14
2
+
3
+ * Require [ruby] >= 2.0.0.
4
+ * Renamed `uri/query_params/extensions` to `uri/query_params/core_ext`.
5
+ * Removed legacy [ruby] 1.8 code.
6
+ * Fix instance variable warnings in `uri/query_params/mixin`.
7
+
8
+ ### 0.7.2 / 2020-11-29
9
+
10
+ * Use `URI::DEFAULT_PARSER.escape` / `.unescape` instead of the deprecated
11
+ `URI.escape` / `URI.unescape`.
12
+
13
+ ### 0.7.1 / 2015-06-11
14
+
15
+ * Fixed a Ruby 2.2 specific bug where `alias`es are defined before the method
16
+ they alias. (@iraupph)
17
+ * Removed the `URI::Generic#path_query` monkeypatch.
18
+ * Override {URI::Generic#to_s} to call the `query` method overrode by
19
+ {URI::QueryParams::Mixin}, instead of `@query`. Starting in Ruby 2.2.0,
20
+ `path_query` was inlined directly into `URI::Generic#to_s` which broke our
21
+ `path_query` monkeypatch.
22
+
23
+ ### 0.7.0 / 2012-03-27
24
+
25
+ * Inject {URI::QueryParams::Mixin} into {URI::Generic}, so all URIs have
26
+ `query_params`.
27
+ * Inject {URI::QueryParams::Mixin} into `Addressable::URI`, if `addressable/uri`
28
+ is loaded.
29
+
1
30
  ### 0.6.2 / 2012-03-15
2
31
 
3
32
  * Fixed a query parameter ordering issue in {URI::QueryParams.dump},
@@ -26,7 +55,7 @@
26
55
  * Contains RFC 3986 unsafe URI characters.
27
56
  * Use {URI::QueryParams::UNSAFE} in {URI::QueryParams.dump} for safer
28
57
  query strings.
29
- * Added {URI::QueryParams::Mixin#query}:
58
+ * Added `URI::QueryParams::Mixin#query`:
30
59
  * If any query-params are set, dump them out using
31
60
  {URI::QueryParams.dump}.
32
61
  * Renamed `parse_query_params` to
@@ -48,3 +77,4 @@
48
77
 
49
78
  * Initial release.
50
79
 
80
+ [ruby]: https://www.ruby-lang.org/
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'addressable'
7
+ end
8
+
9
+ group :development do
10
+ gem 'rake'
11
+ gem 'rubygems-tasks', '~> 0.2'
12
+
13
+ gem 'rspec', '~> 3.0'
14
+
15
+ gem 'kramdown'
16
+ gem 'yard', '~> 0.9'
17
+ gem 'yard-spellcheck', require: false
18
+ end
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2012 Hal Brodigan
1
+ Copyright (c) 2010-2022 Hal Brodigan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,33 +1,48 @@
1
1
  # URI query_params
2
2
 
3
- * [Source](http://github.com/postmodern/uri-query_params)
4
- * [Issues](http://github.com/postmodern/uri-query_params/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
- * [Email](mailto:postmodern.mod3 at gmail.com)
7
6
 
8
7
  ## Description
9
8
 
10
9
  Allows access to the query component of the URI as a Hash. This is similar
11
- to `$_GET` from PHP, except available on any {URI::HTTP} object.
10
+ to `$_GET` from PHP, except available on any Ruby URI object.
12
11
 
13
12
  ## Examples
14
13
 
15
14
  Inspecting the URI query_params:
16
15
 
17
- require 'uri/query_params'
18
-
19
- url = URI('http://www.google.com/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&hs=1HY&q=bob+ross&btnG=Search')
20
- url.query_params
21
- # => {"btnG"=>"Search", "hs"=>"1HY", "rls"=>"org.mozilla:en-US:official", "client"=>"firefox-a", "hl"=>"en", "q"=>"bob+ross"}
16
+ ```ruby
17
+ require 'uri/query_params'
22
18
 
23
- url.query_params['q']
24
- # => "bob+ross"
19
+ url = URI('http://www.google.com/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&hs=1HY&q=bob+ross&btnG=Search')
20
+ url.query_params
21
+ # => {"btnG"=>"Search", "hs"=>"1HY", "rls"=>"org.mozilla:en-US:official", "client"=>"firefox-a", "hl"=>"en", "q"=>"bob+ross"}
22
+
23
+ url.query_params['q']
24
+ # => "bob+ross"
25
+ ```
25
26
 
26
27
  Setting the URI query_params:
27
28
 
28
- url.query_params['q'] = 'Upright Citizens Brigade'
29
- url.to_s
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"
29
+ ```ruby
30
+ url.query_params['q'] = 'Upright Citizens Brigade'
31
+ url.to_s
32
+ # => "http://www.google.com/search?btnG=Search&hs=1HY&rls=org.mozilla:en-US:official&client=firefox-a&hl=en&q=Upright%20Citizens%20Brigade"
33
+ ```
34
+
35
+ Parsing URI query_params embedded within the Fragment Identifier:
36
+
37
+ ```ruby
38
+ url = URI('https://twitter.com/#!/download?lang=en&logged_out=1')
39
+ URI(url.fragment).query_params
40
+ # => {"logged_out"=>"1", "lang"=>"en"}
41
+ ```
42
+
43
+ ## Requirements
44
+
45
+ * [ruby] >= 2.0.0
31
46
 
32
47
  ## Install
33
48
 
@@ -35,6 +50,8 @@ Setting the URI query_params:
35
50
 
36
51
  ## License
37
52
 
38
- Copyright (c) 2010-2012 Hal Brodigan
53
+ Copyright (c) 2010-2022 Hal Brodigan
39
54
 
40
55
  See {file:LICENSE.txt} for license information.
56
+
57
+ [ruby]: https://www.ruby-lang.org/
data/Rakefile CHANGED
@@ -1,36 +1,12 @@
1
1
  require 'rubygems'
2
- require 'rake'
3
2
 
4
- begin
5
- gem 'ore-tasks', '~> 0.4'
6
- require 'ore/tasks'
3
+ require 'rubygems/tasks'
4
+ Gem::Tasks.new
7
5
 
8
- Ore::Tasks.new
9
- rescue LoadError => e
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
- begin
28
- gem 'yard', '~> 0.6.0'
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,19 @@ 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: http://github.com/postmodern/uri-query_params
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
+ metadata:
11
+ documentation_uri: https://rubydoc.info/gems/uri-query_params
12
+ source_code_uri: https://github.com/postmodern/uri-query_params.rb
13
+ bug_tracker_uri: https://github.com/postmodern/uri-query_params.rb/issues
14
+ changelog_uri: https://github.com/postmodern/uri-query_params.rb/blob/master/ChangeLog.md
15
+ rubygems_mfa_required: 'true'
16
+
17
+ required_ruby_version: ">= 2.0.0"
18
+
10
19
  development_dependencies:
11
- ore-tasks: ~> 0.4
12
- rspec: ~> 2.4
13
- yard: ~> 0.6
20
+ bundler: ~> 2.0
@@ -0,0 +1,11 @@
1
+ require 'uri/query_params/mixin'
2
+
3
+ require 'addressable/uri'
4
+
5
+ module Addressable
6
+ class URI
7
+
8
+ include ::URI::QueryParams::Mixin
9
+
10
+ end
11
+ end
@@ -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
@@ -0,0 +1 @@
1
+ require 'uri/query_params/core_ext/uri/generic'
@@ -0,0 +1,2 @@
1
+ require 'uri/query_params/core_ext/uri'
2
+ require 'uri/query_params/core_ext/addressable/uri' if defined?(Addressable)
@@ -0,0 +1 @@
1
+ require 'uri/query_params/core_ext/addressable/uri'
@@ -0,0 +1 @@
1
+ require 'uri/query_params/core_ext/uri/generic'
@@ -0,0 +1 @@
1
+ require 'uri/query_params/core_ext/uri'
@@ -1,2 +1 @@
1
- require 'uri/query_params/extensions/http'
2
- require 'uri/query_params/extensions/https'
1
+ require 'uri/query_params/core_ext'
@@ -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 defined?(@query_params) && @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 defined?(@query_params) && @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
- protected
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
@@ -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
- def QueryParams.parse(query_string)
42
+ # @api semipublic
43
+ #
44
+ def self.parse(query_string)
43
45
  query_params = {}
44
46
 
45
47
  if query_string
@@ -48,10 +50,8 @@ module URI
48
50
  next if param.empty?
49
51
 
50
52
  name, value = param.split('=',2)
51
- value = if value
52
- URI.unescape(value)
53
- else
54
- ''
53
+ value = if value then URI::DEFAULT_PARSER.unescape(value)
54
+ else ''
55
55
  end
56
56
 
57
57
  yield(name,value) if block_given?
@@ -62,6 +62,28 @@ module URI
62
62
  return query_params
63
63
  end
64
64
 
65
+ #
66
+ # Escapes a URI query param value.
67
+ #
68
+ # @param [Array, true, false, nil, #to_s] value
69
+ # The query param value to escape.
70
+ #
71
+ # @return [String]
72
+ # The raw escaped query param value.
73
+ #
74
+ # @since 0.7.1
75
+ #
76
+ # @api semipublic
77
+ #
78
+ def self.escape(value)
79
+ case value
80
+ when Array then URI::DEFAULT_PARSER.escape(value.join(' '),UNSAFE)
81
+ when true then 'active'
82
+ when false, nil then ''
83
+ else URI::DEFAULT_PARSER.escape(value.to_s,UNSAFE)
84
+ end
85
+ end
86
+
65
87
  #
66
88
  # Dumps the URI query params.
67
89
  #
@@ -85,28 +107,12 @@ module URI
85
107
  #
86
108
  # @since 0.5.0
87
109
  #
88
- def QueryParams.dump(query_params)
89
- query = []
90
-
91
- # explicitly re-order the Hash on Ruby 1.8.x
92
- query_params.rehash if RUBY_VERSION < '1.9'
93
-
94
- query_params.each do |name,value|
95
- value = case 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
105
-
106
- query << "#{name}=#{value}"
107
- end
108
-
109
- return query.join('&')
110
+ # @api semipublic
111
+ #
112
+ def self.dump(query_params)
113
+ query_params.map { |name,value|
114
+ "#{name}=#{escape(value)}"
115
+ }.join('&')
110
116
  end
111
117
 
112
118
  end
@@ -1,6 +1,6 @@
1
1
  module URI
2
2
  module QueryParams
3
3
  # uri-query_params version
4
- VERSION = '0.6.2'
4
+ VERSION = '0.8.0'
5
5
  end
6
6
  end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+ require 'query_params_mixin_examples'
3
+ require 'uri/query_params/core_ext/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
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+ require 'query_params_mixin_examples'
3
+ require 'uri/query_params/core_ext/uri'
4
+
5
+ describe URI::Generic do
6
+ let(:uri) { URI('/page.php') }
7
+
8
+ it_should_behave_like "URI::QueryParams::Mixin"
9
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
  require 'query_params_mixin_examples'
3
- require 'uri/query_params/extensions/http'
3
+ require 'uri/query_params/core_ext/uri'
4
4
 
5
5
  describe URI::HTTP do
6
6
  let(:uri) { URI('http://www.example.com/page.php') }
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'uri/query_params/extensions/addressable/uri'
3
+
4
+ describe 'uri/query_params/extensions/addressable/uri' do
5
+ let(:root) { File.expand_path(File.join('..','..','..'),__dir__) }
6
+ let(:path) do
7
+ File.join(root,'lib','uri','query_params','core_ext', 'addressable','uri.rb')
8
+ end
9
+
10
+ it "must require 'uri/query_params/core_ext/addressable/uri'" do
11
+ expect($LOADED_FEATURES).to include(path)
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'uri/query_params/extensions/uri/generic'
3
+
4
+ describe 'uri/query_params/extensions/uri/generic' do
5
+ let(:root) { File.expand_path(File.join('..','..','..'),__dir__) }
6
+ let(:path) do
7
+ File.join(root,'lib','uri','query_params','core_ext', 'uri','generic.rb')
8
+ end
9
+
10
+ it "must require 'uri/query_params/core_ext/uri/generic'" do
11
+ expect($LOADED_FEATURES).to include(path)
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ require 'uri/query_params/extensions/uri'
3
+
4
+ describe 'uri/query_params/extensions/uri' do
5
+ let(:root) { File.expand_path(File.join('..','..'),__dir__) }
6
+ let(:path) { File.join(root,'lib','uri','query_params','core_ext', 'uri.rb') }
7
+
8
+ it "must require 'uri/query_params/core_ext/uri'" do
9
+ expect($LOADED_FEATURES).to include(path)
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+ require 'uri/query_params/extensions'
3
+
4
+ describe 'uri/query_params/extensions' do
5
+ let(:root) { File.expand_path('..',__dir__) }
6
+ let(:path) { File.join(root,'lib','uri','query_params','core_ext.rb') }
7
+
8
+ it "must require 'uri/query_params/core_ext'" do
9
+ expect($LOADED_FEATURES).to include(path)
10
+ end
11
+ end
@@ -10,62 +10,77 @@ shared_examples_for "URI::QueryParams::Mixin" do
10
10
 
11
11
  before(:each) { uri.query = query }
12
12
 
13
- it "should include QueryParams" do
14
- subject.class.should include(URI::QueryParams::Mixin)
15
- end
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
- it "should still provide access to #query" do
18
- uri.query.should == query
19
- end
18
+ it "should still provide access to #query" do
19
+ expect(uri.query).to eq(query)
20
+ end
20
21
 
21
- it "should provide #query_params" do
22
- should respond_to(:query_params)
22
+ it "should provide #query_params" do
23
+ is_expected.to respond_to(:query_params)
24
+ end
23
25
  end
24
26
 
25
- it "should update #query_params after #query is set" do
26
- subject.query = 'u=2'
27
- subject.query_params['u'].should == '2'
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
- it "should dump out the #query_params when accessing #query" do
31
- subject.query_params = {'u' => '3'}
32
- subject.query.should == 'u=3'
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
- it "should properly escape query param values" do
36
- subject.query_params = {'x' => '1&2', 'y' => 'one=two', 'z' => '?'}
36
+ describe "#query=" do
37
+ it "should update #query_params after #query is set" do
38
+ subject.query = 'u=2'
37
39
 
38
- subject.to_s.match(/\?(.+)$/)[1].should == "x=1%262&y=one%3Dtwo&z=%3F"
40
+ expect(subject.query_params['u']).to eq('2')
41
+ end
39
42
  end
40
43
 
41
- it "should deep-copy the query_params Hash" do
42
- original = subject.query_params.object_id
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
- subject.dup.query_params.object_id.should_not == original
45
- subject.clone.query_params.object_id.should_not == original
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.should == Hash
67
+ expect(subject.class).to eq(Hash)
53
68
  end
54
69
 
55
70
  it "should contain params" do
56
- should_not be_empty
71
+ is_expected.not_to be_empty
57
72
  end
58
73
 
59
74
  it "can contain single-word params" do
60
- subject['x'].should == '1'
75
+ expect(subject['x']).to eq('1')
61
76
  end
62
77
 
63
78
  it "can contain multi-word params" do
64
- subject['y'].should == 'one two'
79
+ expect(subject['y']).to eq('one two')
65
80
  end
66
81
 
67
82
  it "can contain empty params" do
68
- subject['z'].should be_empty
83
+ expect(subject['z']).to be_empty
69
84
  end
70
85
  end
71
86
  end
@@ -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('').should be_empty
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').should == {'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').should have_key('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.should have_key('x')
24
- query_params['x'].should be_empty
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'].should == '1 2'
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'].should == '1=2'
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'].should == '1'
43
- query_params['y'].should == '2'
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.should == [['z', '1'], ['z', '2'], ['z', '3']]
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.should == [['z', '1'], ['y', '2'], ['x', '3']]
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({}).should be_empty
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}).should == 'x='
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' => ''}).should == '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}).should == 'x=active'
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}).should == '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]}).should == 'x=1%202'
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'}).should == '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
@@ -1,2 +1 @@
1
- gem 'rspec', '~> 2.4'
2
1
  require 'rspec'
@@ -2,126 +2,60 @@
2
2
 
3
3
  require 'yaml'
4
4
 
5
- Gem::Specification.new do |gemspec|
6
- files = if File.directory?('.git')
7
- `git ls-files`.split($/)
8
- elsif File.directory?('.hg')
9
- `hg manifest`.split($/)
10
- elsif File.directory?('.svn')
11
- `svn ls -R`.split($/).select { |path| File.file?(path) }
12
- else
13
- Dir['{**/}{.*,*}'].select { |path| File.file?(path) }
14
- end
5
+ Gem::Specification.new do |gem|
6
+ gemspec = YAML.load_file('gemspec.yml')
15
7
 
16
- filter_files = lambda { |paths|
17
- case paths
18
- when Array
19
- (files & paths)
20
- when String
21
- (files & Dir[paths])
22
- end
23
- }
24
-
25
- version = {
26
- :file => 'lib/uri/query_params/version.rb',
27
- :constant => 'URI::QueryParams::VERSION'
28
- }
29
-
30
- defaults = {
31
- 'name' => File.basename(File.dirname(__FILE__)),
32
- 'files' => files,
33
- 'executables' => filter_files['bin/*'].map { |path| File.basename(path) },
34
- 'test_files' => filter_files['{test/{**/}*_test.rb,spec/{**/}*_spec.rb}'],
35
- 'extra_doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}'],
36
- }
37
-
38
- metadata = defaults.merge(YAML.load_file('gemspec.yml'))
39
-
40
- gemspec.name = metadata.fetch('name',defaults[:name])
41
- gemspec.version = if metadata['version']
42
- metadata['version']
43
- elsif File.file?(version[:file])
44
- require File.join('.',version[:file])
45
- eval(version[:constant])
46
- end
47
-
48
- gemspec.summary = metadata.fetch('summary',metadata['description'])
49
- gemspec.description = metadata.fetch('description',metadata['summary'])
50
-
51
- case metadata['license']
52
- when Array
53
- gemspec.licenses = metadata['license']
54
- when String
55
- gemspec.license = metadata['license']
56
- end
57
-
58
- case metadata['authors']
59
- when Array
60
- gemspec.authors = metadata['authors']
61
- when String
62
- gemspec.author = metadata['authors']
63
- end
8
+ gem.name = gemspec.fetch('name')
9
+ gem.version = gemspec.fetch('version') do
10
+ lib_dir = File.join(File.dirname(__FILE__),'lib')
11
+ $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
64
12
 
65
- gemspec.email = metadata['email']
66
- gemspec.homepage = metadata['homepage']
13
+ require 'uri/query_params/version'
14
+ URI::QueryParams::VERSION
15
+ end
67
16
 
68
- case metadata['require_paths']
69
- when Array
70
- gemspec.require_paths = metadata['require_paths']
71
- when String
72
- gemspec.require_path = metadata['require_paths']
73
- end
17
+ gem.summary = gemspec['summary']
18
+ gem.description = gemspec['description']
19
+ gem.licenses = Array(gemspec['license'])
20
+ gem.authors = Array(gemspec['authors'])
21
+ gem.email = gemspec['email']
22
+ gem.homepage = gemspec['homepage']
23
+ gem.metadata = gemspec['metadata'] if gemspec['metadata']
74
24
 
75
- gemspec.files = filter_files[metadata['files']]
25
+ glob = lambda { |patterns| gem.files & Dir[*patterns] }
76
26
 
77
- gemspec.executables = metadata['executables']
78
- gemspec.extensions = metadata['extensions']
27
+ gem.files = `git ls-files`.split($/)
28
+ gem.files = glob[gemspec['files']] if gemspec['files']
79
29
 
80
- if Gem::VERSION < '1.7.'
81
- gemspec.default_executable = gemspec.executables.first
30
+ gem.executables = gemspec.fetch('executables') do
31
+ glob['bin/*'].map { |path| File.basename(path) }
82
32
  end
33
+ gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.'
83
34
 
84
- gemspec.test_files = filter_files[metadata['test_files']]
85
-
86
- unless gemspec.files.include?('.document')
87
- gemspec.extra_rdoc_files = metadata['extra_doc_files']
88
- end
89
-
90
- gemspec.post_install_message = metadata['post_install_message']
91
- gemspec.requirements = metadata['requirements']
92
-
93
- if gemspec.respond_to?(:required_ruby_version=)
94
- gemspec.required_ruby_version = metadata['required_ruby_version']
95
- end
35
+ gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
36
+ gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb']
37
+ gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
96
38
 
97
- if gemspec.respond_to?(:required_rubygems_version=)
98
- gemspec.required_rubygems_version = metadata['required_ruby_version']
99
- end
39
+ gem.require_paths = Array(gemspec.fetch('require_paths') {
40
+ %w[ext lib].select { |dir| File.directory?(dir) }
41
+ })
100
42
 
101
- parse_versions = lambda { |versions|
102
- case versions
103
- when Array
104
- versions.map { |v| v.to_s }
105
- when String
106
- versions.split(/,\s*/)
107
- end
108
- }
43
+ gem.requirements = gemspec['requirements']
44
+ gem.required_ruby_version = gemspec['required_ruby_version']
45
+ gem.required_rubygems_version = gemspec['required_rubygems_version']
46
+ gem.post_install_message = gemspec['post_install_message']
109
47
 
110
- if metadata['dependencies']
111
- metadata['dependencies'].each do |name,versions|
112
- gemspec.add_dependency(name,parse_versions[versions])
113
- end
114
- end
48
+ split = lambda { |string| string.split(/,\s*/) }
115
49
 
116
- if metadata['runtime_dependencies']
117
- metadata['runtime_dependencies'].each do |name,versions|
118
- gemspec.add_runtime_dependency(name,parse_versions[versions])
50
+ if gemspec['dependencies']
51
+ gemspec['dependencies'].each do |name,versions|
52
+ gem.add_dependency(name,split[versions])
119
53
  end
120
54
  end
121
55
 
122
- if metadata['development_dependencies']
123
- metadata['development_dependencies'].each do |name,versions|
124
- gemspec.add_development_dependency(name,parse_versions[versions])
56
+ if gemspec['development_dependencies']
57
+ gemspec['development_dependencies'].each do |name,versions|
58
+ gem.add_development_dependency(name,split[versions])
125
59
  end
126
60
  end
127
61
  end
metadata CHANGED
@@ -1,105 +1,98 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uri-query_params
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
5
- prerelease:
4
+ version: 0.8.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Postmodern
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-03-16 00:00:00.000000000 Z
11
+ date: 2022-01-15 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: ore-tasks
16
- requirement: &19935200 !ruby/object:Gem::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.4'
19
+ version: '2.0'
22
20
  type: :development
23
21
  prerelease: false
24
- version_requirements: *19935200
25
- - !ruby/object:Gem::Dependency
26
- name: rspec
27
- requirement: &19934680 !ruby/object:Gem::Requirement
28
- none: false
22
+ version_requirements: !ruby/object:Gem::Requirement
29
23
  requirements:
30
- - - ~>
24
+ - - "~>"
31
25
  - !ruby/object:Gem::Version
32
- version: '2.4'
33
- type: :development
34
- prerelease: false
35
- version_requirements: *19934680
36
- - !ruby/object:Gem::Dependency
37
- name: yard
38
- requirement: &19934200 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ~>
42
- - !ruby/object:Gem::Version
43
- version: '0.6'
44
- type: :development
45
- prerelease: false
46
- version_requirements: *19934200
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
- extra_rdoc_files: []
31
+ extra_rdoc_files:
32
+ - ChangeLog.md
33
+ - LICENSE.txt
34
+ - README.md
52
35
  files:
53
- - .document
54
- - .gemtest
55
- - .gitignore
56
- - .rspec
57
- - .yardopts
36
+ - ".document"
37
+ - ".github/workflows/ruby.yml"
38
+ - ".gitignore"
39
+ - ".rspec"
40
+ - ".yardopts"
58
41
  - ChangeLog.md
42
+ - Gemfile
59
43
  - LICENSE.txt
60
44
  - README.md
61
45
  - Rakefile
62
46
  - gemspec.yml
63
47
  - lib/uri/query_params.rb
48
+ - lib/uri/query_params/core_ext.rb
49
+ - lib/uri/query_params/core_ext/addressable/uri.rb
50
+ - lib/uri/query_params/core_ext/uri.rb
51
+ - lib/uri/query_params/core_ext/uri/generic.rb
64
52
  - lib/uri/query_params/extensions.rb
65
- - lib/uri/query_params/extensions/http.rb
66
- - lib/uri/query_params/extensions/https.rb
53
+ - lib/uri/query_params/extensions/addressable/uri.rb
54
+ - lib/uri/query_params/extensions/uri.rb
55
+ - lib/uri/query_params/extensions/uri/generic.rb
67
56
  - lib/uri/query_params/mixin.rb
68
57
  - lib/uri/query_params/query_params.rb
69
58
  - lib/uri/query_params/version.rb
70
- - spec/extensions/http_spec.rb
71
- - spec/extensions/https_spec.rb
59
+ - spec/core_ext/addressable/uri_spec.rb
60
+ - spec/core_ext/uri/generic_spec.rb
61
+ - spec/core_ext/uri/http_spec.rb
62
+ - spec/extensions/addressable/uri.rb
63
+ - spec/extensions/uri/generic_spec.rb
64
+ - spec/extensions/uri_spec.rb
65
+ - spec/extensions_spec.rb
72
66
  - spec/query_params_mixin_examples.rb
73
67
  - spec/query_params_spec.rb
74
68
  - spec/spec_helper.rb
75
69
  - uri-query_params.gemspec
76
- homepage: http://github.com/postmodern/uri-query_params
70
+ homepage: https://github.com/postmodern/uri-query_params
77
71
  licenses:
78
72
  - MIT
79
- post_install_message:
73
+ metadata:
74
+ documentation_uri: https://rubydoc.info/gems/uri-query_params
75
+ source_code_uri: https://github.com/postmodern/uri-query_params.rb
76
+ bug_tracker_uri: https://github.com/postmodern/uri-query_params.rb/issues
77
+ changelog_uri: https://github.com/postmodern/uri-query_params.rb/blob/master/ChangeLog.md
78
+ rubygems_mfa_required: 'true'
79
+ post_install_message:
80
80
  rdoc_options: []
81
81
  require_paths:
82
82
  - lib
83
83
  required_ruby_version: !ruby/object:Gem::Requirement
84
- none: false
85
84
  requirements:
86
- - - ! '>='
85
+ - - ">="
87
86
  - !ruby/object:Gem::Version
88
- version: '0'
87
+ version: 2.0.0
89
88
  required_rubygems_version: !ruby/object:Gem::Requirement
90
- none: false
91
89
  requirements:
92
- - - ! '>='
90
+ - - ">="
93
91
  - !ruby/object:Gem::Version
94
92
  version: '0'
95
93
  requirements: []
96
- rubyforge_project:
97
- rubygems_version: 1.8.15
98
- signing_key:
99
- specification_version: 3
94
+ rubygems_version: 3.2.22
95
+ signing_key:
96
+ specification_version: 4
100
97
  summary: Access the query parameters of a URI, just like $_GET in PHP.
101
- test_files:
102
- - spec/extensions/http_spec.rb
103
- - spec/extensions/https_spec.rb
104
- - spec/query_params_spec.rb
105
- has_rdoc:
98
+ test_files: []
data/.gemtest DELETED
File without changes
@@ -1,11 +0,0 @@
1
- require 'uri/query_params/mixin'
2
-
3
- require 'uri/http'
4
-
5
- module URI
6
- class HTTP < Generic
7
-
8
- include QueryParams::Mixin
9
-
10
- end
11
- end
@@ -1,3 +0,0 @@
1
- require 'uri/query_params/extensions/http'
2
-
3
- require 'uri/https'
@@ -1,9 +0,0 @@
1
- require 'spec_helper'
2
- require 'query_params_mixin_examples'
3
- require 'uri/query_params/extensions/http'
4
-
5
- describe URI::HTTPS do
6
- let(:uri) { URI('https://www.example.com/page.php') }
7
-
8
- it_should_behave_like "URI::QueryParams::Mixin"
9
- end