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 CHANGED
@@ -1,3 +1,4 @@
1
+ Gemfile.lock
1
2
  doc
2
3
  pkg
3
4
  tmp/*
@@ -0,0 +1,6 @@
1
+ ---
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
@@ -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
@@ -0,0 +1,17 @@
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.8'
17
+ end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2012 Hal Brodigan
1
+ Copyright (c) 2010-2015 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,10 +1,12 @@
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
6
  * [Email](mailto:postmodern.mod3 at gmail.com)
7
7
 
8
+ [![Build Status](https://secure.travis-ci.org/postmodern/uri-query_params.svg)](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-2012 Hal Brodigan
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
- gem 'rspec', '~> 2.4'
6
- require 'rspec/core/rake_task'
7
-
8
- RSpec::Core::RakeTask.new
2
+ require 'bundler/setup'
9
3
  rescue LoadError => e
10
- task :spec do
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
- begin
18
- gem 'yard', '~> 0.6.0'
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
@@ -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: 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
10
  development_dependencies:
11
- rspec: ~> 2.4
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
- # Parses the query parameters from the query data, populating
16
- # query_params with the parsed parameters.
11
+ # Constructs String from URI
17
12
  #
18
- # @see QueryParams.parse
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
- # @since 0.5.2
18
+ # @see https://github.com/ruby/ruby/blob/v2_2_0/lib/uri/generic.rb#L1338-L1376
21
19
  #
22
- def path_query
23
- if @query_params
24
- str = @path
25
-
26
- unless @query_params.empty?
27
- str += '?' + URI::QueryParams.dump(@query_params)
28
- end
20
+ def to_s
21
+ str = ''
22
+ if @scheme
23
+ str << @scheme
24
+ str << ':'.freeze
25
+ end
29
26
 
30
- str
27
+ if @opaque
28
+ str << @opaque
31
29
  else
32
- # do not rebuild the path-query, if the query_params have not
33
- # been parsed yet
34
- raw_path_query
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
@@ -112,7 +112,7 @@ module URI
112
112
  query_params.each(&block)
113
113
  end
114
114
 
115
- protected
115
+ private
116
116
 
117
117
  #
118
118
  # Parses the query parameters from the query data, populating
@@ -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
@@ -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
- def QueryParams.dump(query_params)
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 = 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
125
+ value = escape(value)
105
126
 
106
127
  query << "#{name}=#{value}"
107
128
  end
@@ -1,6 +1,6 @@
1
1
  module URI
2
2
  module QueryParams
3
3
  # uri-query_params version
4
- VERSION = '0.7.0'
4
+ VERSION = '0.7.1'
5
5
  end
6
6
  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
@@ -1,2 +1 @@
1
- gem 'rspec', '~> 2.4'
2
1
  require 'rspec'
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.0
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: 2012-03-28 00:00:00.000000000 Z
12
+ date: 2015-06-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rspec
16
- requirement: &13944620 !ruby/object:Gem::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: '2.4'
21
+ version: '1.0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *13944620
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.6'
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: http://github.com/postmodern/uri-query_params
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.15
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