go_to_param 1.0.0 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6fa16c7fe969b722bbc7f884c7b2f1b24df75bb7
4
- data.tar.gz: 0e7c3acd3d434566ffeb201eb006a43765dad107
2
+ SHA256:
3
+ metadata.gz: a8742769791ea66237e5decb3e329ed1c2b6a127f072378487b134f45cd8b7a9
4
+ data.tar.gz: cf8134a2f905e96b8e143c67ccae9f931d109c6c6570a6d46b64d4a329275904
5
5
  SHA512:
6
- metadata.gz: bfccf03b703ea760d1b8ae8a81cd238052248b18f70e3044d76856577edbdc40f304602178d4716774427fde0579d0a19062e7bf1c401509fa401d85978e1ee0
7
- data.tar.gz: 45575857ba7c020275d9f1384264b13a4c4892afaefc30864babf7b206197c2f6362b303bf872b8e3b129036d91a0edb546b8244d0a0c45114670371c5c1d26c
6
+ metadata.gz: 1366c2d13bb1cba9f3147eadaa3a092526f70da496a642162a4e0e54da880b095b99335f24a3214ef72dc1fea834a2d0208c801020fefa4218c889d9bfc791e8
7
+ data.tar.gz: c74471045b18e7f076df5eccd804d31e1198064aa8affdf89518af07b420955d96701bcb1469ef8709037e2d306d6589115ac16be9cfec66a054179527b355a9
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## 1.1.2
4
+
5
+ - Fix keyword parameter warning. Thanks to @olleolleolle!
6
+
7
+ ## 1.1.1
8
+
9
+ - Don't raise exceptions if given hash params from hack attempts, such as: `go_to[foo]=bar`.
10
+
11
+ ## Earlier
12
+
13
+ Sorry, no changelog available for earlier versions.
data/README.md CHANGED
@@ -55,6 +55,8 @@ You can pass additional query parameters to include, which could be suitable if
55
55
 
56
56
  Note that these parameters always become transformed into a query string: if you're using Ruby on Rails, they won't be interpreted through your route definitions.
57
57
 
58
+ You can, however, pass a Rails-style `anchor: "foo"` parameter to set the URL fragment (`/example#foo`).
59
+
58
60
 
59
61
  ### hidden_go_to_tag
60
62
 
@@ -1,3 +1,3 @@
1
1
  module GoToParam
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.3"
3
3
  end
data/lib/go_to_param.rb CHANGED
@@ -35,7 +35,7 @@ module GoToParam
35
35
  end
36
36
 
37
37
  def go_to_here_params(additional_query_params = {})
38
- path = go_to_here_path(additional_query_params)
38
+ path = go_to_here_path(**additional_query_params)
39
39
 
40
40
  if path
41
41
  { go_to: path }
@@ -65,16 +65,19 @@ module GoToParam
65
65
  GoToParam.allowed_redirect_prefixes.any? { |prefix| go_to_param_value.start_with?(prefix) }
66
66
  end
67
67
 
68
- def go_to_here_path(additional_query_params = {})
68
+ def go_to_here_path(anchor: nil, **additional_query_params)
69
69
  if request.get?
70
- _go_to_add_query_string_from_hash(_go_to_fullpath, additional_query_params)
70
+ path_without_anchor = _go_to_add_query_string_from_hash(_go_to_fullpath, additional_query_params)
71
+ anchor ? path_without_anchor + "#" + anchor : path_without_anchor
71
72
  else
72
73
  nil
73
74
  end
74
75
  end
75
76
 
76
77
  def go_to_param_value
77
- params[:go_to]
78
+ # We use `to_s` to avoid "not a string" type errors from hack attempts where a hash is passed, e.g. "go_to[foo]=bar".
79
+ value = params[:go_to].to_s
80
+ value == "" ? nil : value
78
81
  end
79
82
 
80
83
  # Named this way to avoid conflicts. TODO: http://thepugautomatic.com/2014/02/private-api/
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: go_to_param
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik N
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-10 00:00:00.000000000 Z
11
+ date: 2021-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -59,18 +59,15 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - ".gitignore"
63
- - Gemfile
62
+ - CHANGELOG.md
64
63
  - README.md
65
- - Rakefile
66
- - go_to_param.gemspec
67
64
  - lib/go_to_param.rb
68
65
  - lib/go_to_param/version.rb
69
- - spec/go_to_param_spec.rb
70
66
  homepage: ''
71
67
  licenses:
72
68
  - MIT
73
- metadata: {}
69
+ metadata:
70
+ rubygems_mfa_required: 'true'
74
71
  post_install_message:
75
72
  rdoc_options: []
76
73
  require_paths:
@@ -86,10 +83,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
83
  - !ruby/object:Gem::Version
87
84
  version: '0'
88
85
  requirements: []
89
- rubyforge_project:
90
- rubygems_version: 2.2.2
86
+ rubygems_version: 3.2.31
91
87
  signing_key:
92
88
  specification_version: 4
93
89
  summary: Rails "go_to" redirection param utilities.
94
- test_files:
95
- - spec/go_to_param_spec.rb
90
+ test_files: []
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in go_to_param.gemspec
4
- gemspec
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
data/go_to_param.gemspec DELETED
@@ -1,22 +0,0 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'go_to_param/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "go_to_param"
7
- spec.version = GoToParam::VERSION
8
- spec.authors = ["Henrik N"]
9
- spec.email = ["henrik@nyh.se"]
10
- spec.summary = %q{Rails "go_to" redirection param utilities.}
11
- spec.homepage = ""
12
- spec.license = "MIT"
13
-
14
- spec.files = `git ls-files`.split($/)
15
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
- spec.require_paths = ["lib"]
18
-
19
- spec.add_development_dependency "bundler", "~> 1.3"
20
- spec.add_development_dependency "rake"
21
- spec.add_development_dependency "rspec"
22
- end
@@ -1,160 +0,0 @@
1
- require_relative "../lib/go_to_param"
2
-
3
- class FakeController
4
- attr_accessor :params, :view_context, :request
5
-
6
- def self.helper_method(*methods)
7
- @helper_methods = methods
8
- end
9
-
10
- def self.helper_methods
11
- @helper_methods
12
- end
13
-
14
- include GoToParam
15
- end
16
-
17
- describe GoToParam do
18
- after { GoToParam.reset_allowed_redirect_prefixes }
19
-
20
- let(:controller) { FakeController.new }
21
-
22
- describe "#hidden_go_to_tag" do
23
- it "becomes a helper method" do
24
- expect(FakeController.helper_methods).to include :hidden_go_to_tag
25
- end
26
-
27
- it "adds a hidden field tag" do
28
- controller.params = { go_to: "/example", id: "1" }
29
- view = double
30
- controller.view_context = view
31
-
32
- expect(view).to receive(:hidden_field_tag).with(:go_to, "/example")
33
- controller.hidden_go_to_tag
34
- end
35
- end
36
-
37
- describe "#hidden_go_to_here_tag" do
38
- it "becomes a helper method" do
39
- expect(FakeController.helper_methods).to include :hidden_go_to_here_tag
40
- end
41
-
42
- it "adds a hidden field tag" do
43
- controller.request = double(get?: true, fullpath: "/example")
44
- view = double
45
- controller.view_context = view
46
-
47
- expect(view).to receive(:hidden_field_tag).with(:go_to, "/example")
48
- controller.hidden_go_to_here_tag
49
- end
50
-
51
- # Tested in more detail in #go_to_here_params.
52
- it "accepts additional query parameters" do
53
- controller.request = double(get?: true, fullpath: "/example?a=1")
54
- view = double
55
- controller.view_context = view
56
-
57
- expect(view).to receive(:hidden_field_tag).with(:go_to, "/example?a=1&b=1+2")
58
- controller.hidden_go_to_here_tag(b: "1 2")
59
- end
60
- end
61
-
62
- describe "#go_to_params" do
63
- it "becomes a helper method" do
64
- expect(FakeController.helper_methods).to include :go_to_params
65
- end
66
-
67
- it "includes the go_to parameter" do
68
- controller.params = { go_to: "/example", id: "1" }
69
-
70
- expect(controller.go_to_params).to eq({ go_to: "/example" })
71
- end
72
-
73
- it "accepts additional parameters" do
74
- controller.params = { go_to: "/example", id: "1" }
75
-
76
- expect(controller.go_to_params(a: "b")).to eq({ go_to: "/example", a: "b" })
77
- end
78
- end
79
-
80
- describe "#go_to_here_params" do
81
- it "becomes a helper method" do
82
- expect(FakeController.helper_methods).to include :go_to_here_params
83
- end
84
-
85
- it "gets the request path as the go_to parameter" do
86
- controller.request = double(get?: true, fullpath: "/example")
87
- expect(controller.go_to_here_params).to eq({ go_to: "/example" })
88
- end
89
-
90
- it "returns an empty hash for a non-GET request" do
91
- controller.request = double(get?: false, fullpath: "/example")
92
- expect(controller.go_to_here_params).to eq({})
93
- end
94
-
95
- it "accepts additional query parameters" do
96
- controller.request = double(get?: true, fullpath: "/example")
97
- expect(controller.go_to_here_params(foo: "1 2", bar: 3)).to eq({ go_to: "/example?foo=1+2&bar=3" })
98
-
99
- # Handles pre-existing "?"
100
- controller.request = double(get?: true, fullpath: "/example?foo")
101
- expect(controller.go_to_here_params(bar: 3)).to eq({ go_to: "/example?foo&bar=3" })
102
- end
103
-
104
- it "makes sure the go_to path is valid UTF-8" do
105
- weird_path = "\xE0\x80\x80weird\330stuff".force_encoding("ASCII-8BIT")
106
- replacement = "\uFFFD" # The Unicode "Replacement Character".
107
-
108
- controller.request = double(get?: true, fullpath: weird_path)
109
-
110
- go_to_value = controller.go_to_here_params[:go_to]
111
-
112
- expect(go_to_value.encoding).to eq(Encoding::UTF_8)
113
- expect(go_to_value).to eq("#{replacement}#{replacement}#{replacement}weird#{replacement}stuff")
114
- end
115
- end
116
-
117
- describe "#go_to_path" do
118
- it "becomes a helper method" do
119
- expect(FakeController.helper_methods).to include :go_to_path
120
- end
121
-
122
- it "is the go_to parameter value" do
123
- controller.params = { go_to: "/example", id: "1" }
124
- expect(controller.go_to_path).to eq("/example")
125
- end
126
-
127
- it "is nil if the parameter value is not a relative path" do
128
- controller.params = { go_to: "http://evil.com", id: "1" }
129
- expect(controller.go_to_path).to be_nil
130
- end
131
-
132
- it "respects custom allowed redirect prefixes" do
133
- GoToParam.allow_redirect_prefix("myapp://")
134
-
135
- controller.params = { go_to: "myapp://", id: "1" }
136
- expect(controller.go_to_path).to eq("myapp://")
137
- end
138
- end
139
-
140
- describe "#go_to_path_or" do
141
- it "becomes a helper method" do
142
- expect(FakeController.helper_methods).to include :go_to_path_or
143
- end
144
-
145
- it "is the go_to parameter value" do
146
- controller.params = { go_to: "/example", id: "1" }
147
- expect(controller.go_to_path_or("/default")).to eq("/example")
148
- end
149
-
150
- it "falls back if the go_to param is blank" do
151
- controller.params = { go_to: "", id: "1" }
152
- expect(controller.go_to_path_or("/default")).to eq("/default")
153
- end
154
-
155
- it "falls back if the go_to param is not allowed" do
156
- controller.params = { go_to: "http://evil.com", id: "1" }
157
- expect(controller.go_to_path_or("/default")).to eq("/default")
158
- end
159
- end
160
- end