uri-query_params 0.8.0 → 0.8.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 +4 -4
- data/.github/workflows/ruby.yml +3 -3
- data/.gitignore +1 -0
- data/ChangeLog.md +11 -0
- data/Gemfile +3 -1
- data/LICENSE.txt +1 -1
- data/README.md +3 -3
- data/lib/uri/query_params/core_ext/addressable/uri.rb +2 -0
- data/lib/uri/query_params/core_ext/uri/generic.rb +14 -12
- data/lib/uri/query_params/core_ext/uri/http.rb +41 -0
- data/lib/uri/query_params/core_ext/uri.rb +4 -1
- data/lib/uri/query_params/core_ext.rb +4 -2
- data/lib/uri/query_params/extensions/addressable/uri.rb +3 -1
- data/lib/uri/query_params/extensions/uri/generic.rb +3 -1
- data/lib/uri/query_params/extensions/uri.rb +3 -1
- data/lib/uri/query_params/extensions.rb +3 -1
- data/lib/uri/query_params/mixin.rb +3 -1
- data/lib/uri/query_params/query_params.rb +4 -2
- data/lib/uri/query_params/version.rb +3 -1
- data/lib/uri/query_params.rb +4 -2
- data/spec/core_ext/addressable/uri_spec.rb +1 -1
- data/spec/core_ext/uri/generic_spec.rb +1 -1
- data/spec/core_ext/uri/http_spec.rb +70 -2
- data/spec/query_params_mixin_examples.rb +9 -12
- data/spec/spec_helper.rb +3 -0
- data/uri-query_params.gemspec +1 -4
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd44e30ac1cd40c95e093e8d089ba7f1a45c713efb447bdd0b0a3450450ee8db
|
4
|
+
data.tar.gz: 2583cc6cbdc4b63a09161629edf101d6f4db148d712ae4172291d6a8a0c039b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 550c07c019eb59350688181613c147aeffb74d8f7728dd85f81df6ad178b1d17ee4cde18bf1a63fcf280abc4ada2ca95d6db8427086f40bd3b0301cc1354fddd
|
7
|
+
data.tar.gz: 0f8b1c905f632864282bc8d46d07dc75eb48a6217d655265b7b9bb9f7b238f0af4e2e1da927e9fd42786196eef1d7d16242cdf4ca42ba614c9d94199d2c36ddb
|
data/.github/workflows/ruby.yml
CHANGED
data/.gitignore
CHANGED
data/ChangeLog.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
### 0.8.2 / 2024-01-25
|
2
|
+
|
3
|
+
* Switched to using `require_relative` to improve load-times.
|
4
|
+
* Added `# frozen_string_literal: true` to all files.
|
5
|
+
|
6
|
+
### 0.8.1 / 2022-10-22
|
7
|
+
|
8
|
+
* Updated {URI::Generic#to_s} to ruby-3.0.0.
|
9
|
+
* Override {URI::HTTP#request_uri} to be aware of
|
10
|
+
{URI::QueryParams::Mixin#query_params}.
|
11
|
+
|
1
12
|
### 0.8.0 / 2022-01-14
|
2
13
|
|
3
14
|
* Require [ruby] >= 2.0.0.
|
data/Gemfile
CHANGED
@@ -10,9 +10,11 @@ group :development do
|
|
10
10
|
gem 'rake'
|
11
11
|
gem 'rubygems-tasks', '~> 0.2'
|
12
12
|
|
13
|
-
gem 'rspec',
|
13
|
+
gem 'rspec', '~> 3.0'
|
14
|
+
gem 'simplecov', '~> 0.20'
|
14
15
|
|
15
16
|
gem 'kramdown'
|
17
|
+
gem 'redcarpet', platform: :mri
|
16
18
|
gem 'yard', '~> 0.9'
|
17
19
|
gem 'yard-spellcheck', require: false
|
18
20
|
end
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -46,12 +46,12 @@ URI(url.fragment).query_params
|
|
46
46
|
|
47
47
|
## Install
|
48
48
|
|
49
|
-
|
49
|
+
```shell
|
50
|
+
$ gem install uri-query_params
|
51
|
+
```
|
50
52
|
|
51
53
|
## License
|
52
54
|
|
53
|
-
Copyright (c) 2010-2022 Hal Brodigan
|
54
|
-
|
55
55
|
See {file:LICENSE.txt} for license information.
|
56
56
|
|
57
57
|
[ruby]: https://www.ruby-lang.org/
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../mixin'
|
2
4
|
|
3
5
|
require 'uri/generic'
|
4
6
|
|
@@ -11,44 +13,44 @@ module URI
|
|
11
13
|
# Constructs String from URI
|
12
14
|
#
|
13
15
|
# @note
|
14
|
-
# This is the `URI::Generic#to_s` method from Ruby
|
16
|
+
# This is the `URI::Generic#to_s` method from Ruby 3.0.0, with the minor
|
15
17
|
# modification of calling the `query` method overrode by
|
16
18
|
# {URI::QueryParams::Mixin}, instead of `@query`.
|
17
19
|
#
|
18
|
-
# @see https://github.com/ruby/ruby/blob/
|
20
|
+
# @see https://github.com/ruby/ruby/blob/v3_0.0/lib/uri/generic.rb#L1330-L1368
|
19
21
|
#
|
20
22
|
def to_s
|
21
|
-
str = ''
|
23
|
+
str = ''.dup
|
22
24
|
if @scheme
|
23
25
|
str << @scheme
|
24
|
-
str << ':'
|
26
|
+
str << ':'
|
25
27
|
end
|
26
28
|
|
27
29
|
if @opaque
|
28
30
|
str << @opaque
|
29
31
|
else
|
30
|
-
if @host
|
31
|
-
str << '//'
|
32
|
+
if @host || %w[file postgres].include?(@scheme)
|
33
|
+
str << '//'
|
32
34
|
end
|
33
35
|
if self.userinfo
|
34
36
|
str << self.userinfo
|
35
|
-
str << '@'
|
37
|
+
str << '@'
|
36
38
|
end
|
37
39
|
if @host
|
38
40
|
str << @host
|
39
41
|
end
|
40
42
|
if @port && @port != self.default_port
|
41
|
-
str << ':'
|
43
|
+
str << ':'
|
42
44
|
str << @port.to_s
|
43
45
|
end
|
44
46
|
str << @path
|
45
|
-
if query
|
46
|
-
str << '?'
|
47
|
+
if (query = self.query)
|
48
|
+
str << '?'
|
47
49
|
str << query
|
48
50
|
end
|
49
51
|
end
|
50
52
|
if @fragment
|
51
|
-
str << '#'
|
53
|
+
str << '#'
|
52
54
|
str << @fragment
|
53
55
|
end
|
54
56
|
str
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'generic'
|
4
|
+
|
5
|
+
require 'uri/http'
|
6
|
+
|
7
|
+
module URI
|
8
|
+
class HTTP < Generic
|
9
|
+
|
10
|
+
alias raw_request_uri request_uri
|
11
|
+
|
12
|
+
#
|
13
|
+
# Returns the full path for an HTTP request.
|
14
|
+
#
|
15
|
+
# @return [String, nil]
|
16
|
+
# The request URI (path + query params) or `nil` if the URI has no
|
17
|
+
# path.
|
18
|
+
#
|
19
|
+
# @example
|
20
|
+
# uri.path = '/path'
|
21
|
+
# uri.query_params['foo'] = '1'
|
22
|
+
# uri.query_params['bar'] = '2'
|
23
|
+
# uri.request_uri
|
24
|
+
# # => "/path?foo=1&bar=2"
|
25
|
+
#
|
26
|
+
def request_uri
|
27
|
+
if defined?(@query_params) && @query_params
|
28
|
+
return unless @path
|
29
|
+
|
30
|
+
query = URI::QueryParams.dump(@query_params)
|
31
|
+
|
32
|
+
url = "#{@path}?#{query}"
|
33
|
+
url = "/#{url}" unless url.start_with?('/')
|
34
|
+
url
|
35
|
+
else
|
36
|
+
raw_request_uri
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'uri/common'
|
2
4
|
|
3
5
|
module URI
|
@@ -78,8 +80,8 @@ module URI
|
|
78
80
|
def self.escape(value)
|
79
81
|
case value
|
80
82
|
when Array then URI::DEFAULT_PARSER.escape(value.join(' '),UNSAFE)
|
81
|
-
when true then 'active'
|
82
|
-
when false, nil then ''
|
83
|
+
when true then String.new('active')
|
84
|
+
when false, nil then String.new('')
|
83
85
|
else URI::DEFAULT_PARSER.escape(value.to_s,UNSAFE)
|
84
86
|
end
|
85
87
|
end
|
data/lib/uri/query_params.rb
CHANGED
@@ -3,7 +3,7 @@ require 'query_params_mixin_examples'
|
|
3
3
|
require 'uri/query_params/core_ext/addressable/uri'
|
4
4
|
|
5
5
|
describe Addressable::URI do
|
6
|
-
|
6
|
+
subject { described_class.parse('http://www.example.com/page.php') }
|
7
7
|
|
8
8
|
it_should_behave_like "URI::QueryParams::Mixin"
|
9
9
|
end
|
@@ -1,9 +1,77 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'query_params_mixin_examples'
|
3
|
-
require 'uri/query_params/core_ext/uri'
|
3
|
+
require 'uri/query_params/core_ext/uri/http'
|
4
4
|
|
5
5
|
describe URI::HTTP do
|
6
|
-
|
6
|
+
subject { URI.parse("http://www.example.com/page.php") }
|
7
7
|
|
8
8
|
it_should_behave_like "URI::QueryParams::Mixin"
|
9
|
+
|
10
|
+
describe "#request_uri" do
|
11
|
+
context "when #query_params is set" do
|
12
|
+
let(:query_params) do
|
13
|
+
{'x' => '1', 'y' => '2'}
|
14
|
+
end
|
15
|
+
|
16
|
+
before { subject.query_params = query_params }
|
17
|
+
|
18
|
+
context "and when #path is set" do
|
19
|
+
it "must return the #path and #query_params" do
|
20
|
+
expect(subject.request_uri).to eq("#{subject.path}?x=#{query_params['x']}&y=#{query_params['y']}")
|
21
|
+
end
|
22
|
+
|
23
|
+
context "but #path does not start with a '/' character" do
|
24
|
+
subject { URI.parse("http://www.example.com") }
|
25
|
+
|
26
|
+
it "must prepend a '/' character" do
|
27
|
+
expect(subject.request_uri).to eq("/#{subject.path}?x=#{query_params['x']}&y=#{query_params['y']}")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "but #path is not set" do
|
33
|
+
before { subject.path = nil }
|
34
|
+
|
35
|
+
it "must return nil" do
|
36
|
+
expect(subject.request_uri).to be(nil)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when #query_params is not set" do
|
42
|
+
context "and when #path is set" do
|
43
|
+
context "and when #query is set" do
|
44
|
+
let(:query) { 'x=1&y=2' }
|
45
|
+
|
46
|
+
subject { URI("http://www.example.com/page.php?#{query}") }
|
47
|
+
|
48
|
+
it "must return the #path and #query" do
|
49
|
+
expect(subject.request_uri).to eq("#{subject.path}?#{subject.query}")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "but when #query is not set" do
|
54
|
+
it "must return #path" do
|
55
|
+
expect(subject.request_uri).to eq(subject.path)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "but #path does not start with a '/' character" do
|
60
|
+
subject { URI.parse("http://www.example.com") }
|
61
|
+
|
62
|
+
it "must prepend a '/' character" do
|
63
|
+
expect(subject.request_uri).to eq("/#{subject.path}")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "but #path is not set" do
|
69
|
+
before { subject.path = nil }
|
70
|
+
|
71
|
+
it "must return nil" do
|
72
|
+
expect(subject.request_uri).to be(nil)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
9
77
|
end
|
@@ -6,9 +6,7 @@ require 'uri'
|
|
6
6
|
shared_examples_for "URI::QueryParams::Mixin" do
|
7
7
|
let(:query) { 'x=1&y=one%20two&z' }
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
before(:each) { uri.query = query }
|
9
|
+
before { subject.query = query }
|
12
10
|
|
13
11
|
context "when included" do
|
14
12
|
it "should include QueryParams::Mixin" do
|
@@ -16,11 +14,11 @@ shared_examples_for "URI::QueryParams::Mixin" do
|
|
16
14
|
end
|
17
15
|
|
18
16
|
it "should still provide access to #query" do
|
19
|
-
expect(
|
17
|
+
expect(subject.query).to eq(query)
|
20
18
|
end
|
21
19
|
|
22
20
|
it "should provide #query_params" do
|
23
|
-
|
21
|
+
expect(subject).to respond_to(:query_params)
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
@@ -44,6 +42,7 @@ shared_examples_for "URI::QueryParams::Mixin" do
|
|
44
42
|
describe "#query" do
|
45
43
|
it "should dump out the #query_params when accessing #query" do
|
46
44
|
subject.query_params = {'u' => '3'}
|
45
|
+
|
47
46
|
expect(subject.query).to eq('u=3')
|
48
47
|
end
|
49
48
|
|
@@ -61,26 +60,24 @@ shared_examples_for "URI::QueryParams::Mixin" do
|
|
61
60
|
end
|
62
61
|
|
63
62
|
describe "#query_params" do
|
64
|
-
subject { uri.query_params }
|
65
|
-
|
66
63
|
it "should be a Hash" do
|
67
|
-
expect(subject.class).to eq(Hash)
|
64
|
+
expect(subject.query_params.class).to eq(Hash)
|
68
65
|
end
|
69
66
|
|
70
67
|
it "should contain params" do
|
71
|
-
|
68
|
+
expect(subject.query_params).not_to be_empty
|
72
69
|
end
|
73
70
|
|
74
71
|
it "can contain single-word params" do
|
75
|
-
expect(subject['x']).to eq('1')
|
72
|
+
expect(subject.query_params['x']).to eq('1')
|
76
73
|
end
|
77
74
|
|
78
75
|
it "can contain multi-word params" do
|
79
|
-
expect(subject['y']).to eq('one two')
|
76
|
+
expect(subject.query_params['y']).to eq('one two')
|
80
77
|
end
|
81
78
|
|
82
79
|
it "can contain empty params" do
|
83
|
-
expect(subject['z']).to be_empty
|
80
|
+
expect(subject.query_params['z']).to be_empty
|
84
81
|
end
|
85
82
|
end
|
86
83
|
end
|
data/spec/spec_helper.rb
CHANGED
data/uri-query_params.gemspec
CHANGED
@@ -7,10 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
|
8
8
|
gem.name = gemspec.fetch('name')
|
9
9
|
gem.version = gemspec.fetch('version') do
|
10
|
-
|
11
|
-
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
12
|
-
|
13
|
-
require 'uri/query_params/version'
|
10
|
+
require_relative 'lib/uri/query_params/version'
|
14
11
|
URI::QueryParams::VERSION
|
15
12
|
end
|
16
13
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uri-query_params
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Postmodern
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- lib/uri/query_params/core_ext/addressable/uri.rb
|
50
50
|
- lib/uri/query_params/core_ext/uri.rb
|
51
51
|
- lib/uri/query_params/core_ext/uri/generic.rb
|
52
|
+
- lib/uri/query_params/core_ext/uri/http.rb
|
52
53
|
- lib/uri/query_params/extensions.rb
|
53
54
|
- lib/uri/query_params/extensions/addressable/uri.rb
|
54
55
|
- lib/uri/query_params/extensions/uri.rb
|
@@ -91,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
92
|
- !ruby/object:Gem::Version
|
92
93
|
version: '0'
|
93
94
|
requirements: []
|
94
|
-
rubygems_version: 3.
|
95
|
+
rubygems_version: 3.4.10
|
95
96
|
signing_key:
|
96
97
|
specification_version: 4
|
97
98
|
summary: Access the query parameters of a URI, just like $_GET in PHP.
|