rails-hidden_autocomplete 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +32 -0
- data/app/assets/config/rails_hidden_autocomplete_manifest.js +0 -0
- data/config/initializers/rails-hidden_autocomplete.rb +6 -0
- data/config/routes.rb +2 -0
- data/lib/rails/hidden_autocomplete/action_view/helpers/date_time_selector.rb +24 -0
- data/lib/rails/hidden_autocomplete/action_view/helpers/form_tag_helper.rb +13 -0
- data/lib/rails/hidden_autocomplete/action_view/helpers/tags.rb +16 -0
- data/lib/rails/hidden_autocomplete/action_view/helpers/url_helper.rb +76 -0
- data/lib/rails/hidden_autocomplete/engine.rb +6 -0
- data/lib/rails/hidden_autocomplete/version.rb +5 -0
- data/lib/rails/hidden_autocomplete.rb +10 -0
- data/lib/tasks/rails/hidden_autocomplete_tasks.rake +4 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 714b227121581a2d002269a2255687b039ef2b2e5b18bf1c6e615cae6d3b3aec
|
4
|
+
data.tar.gz: 2f90d31085eceb2b3d0c084b215f2439464c06217bad2f0d22d26f5d9fbfd4e4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3b18e08b4f20d30fb86258c4449c445fcb43518dd20c2962dc3940226e80f0a7ad5ccc720ba45ac40762bc59ed34b216584d044938a4ec8e09496ebd5c3d5c48
|
7
|
+
data.tar.gz: 4bfb358b4018c3ab3919d8d5559735bff7f08d76ac24dde8557371132e41896b2fe04cad5feb915c2545a0a87c75ba2a592b34930669a56a6b25052fb54de7ff
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2021 Ryan Baumann
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# rails-hidden_autocomplete
|
2
|
+
This is a Rails plugin to add `autocomplete="off"` to all hidden form inputs generated by Rails. This is necessary because Firefox has [a long-running bug](https://bugzilla.mozilla.org/show_bug.cgi?id=520561) where it may populate hidden inputs **without** `autocomplete="off"` with completely random values. Since Rails uses hidden fields extensively for CSRF protection and non-standard HTTP methods, this issue is also tracked in the main Rails tracker here: [add autocomplete="OFF" to firefox-proof automagically added hidden fields like method](https://github.com/rails/rails/issues/42610)
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
Using this plugin from a Rails 6 application should automatically override Rails classes which generate hidden form inputs to add an `autocomplete="off"` attribute.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'rails-hidden_autocomplete'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install rails-hidden_autocomplete
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
If you find a place that still emits hidden form inputs without an `autocomplete="off"` attribute, please feel free to submit a pull request to cover it.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Rails::HiddenAutocomplete'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
load 'rails/tasks/statistics.rake'
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'test'
|
28
|
+
t.pattern = 'test/**/*_test.rb'
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
task default: :test
|
File without changes
|
@@ -0,0 +1,6 @@
|
|
1
|
+
Rails.application.reloader.to_prepare do
|
2
|
+
ActionView::Helpers::DateTimeSelector.prepend Rails::HiddenAutocomplete::ActionView::Helpers::DateTimeSelector
|
3
|
+
ActionView::Helpers::FormTagHelper.prepend Rails::HiddenAutocomplete::ActionView::Helpers::FormTagHelper
|
4
|
+
ActionView::Helpers::Tags.prepend Rails::HiddenAutocomplete::ActionView::Helpers::Tags
|
5
|
+
ActionView::Helpers::UrlHelper.prepend Rails::HiddenAutocomplete::ActionView::Helpers::UrlHelper
|
6
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Rails
|
2
|
+
module HiddenAutocomplete
|
3
|
+
module ActionView
|
4
|
+
module Helpers
|
5
|
+
module DateTimeSelector
|
6
|
+
private
|
7
|
+
|
8
|
+
def build_hidden(type, value)
|
9
|
+
select_options = {
|
10
|
+
type: 'hidden',
|
11
|
+
id: input_id_from_type(type),
|
12
|
+
name: input_name_from_type(type),
|
13
|
+
value: value,
|
14
|
+
autocomplete: 'off'
|
15
|
+
}.merge!(@html_options.slice(:disabled))
|
16
|
+
select_options[:disabled] = 'disabled' if @options[:disabled]
|
17
|
+
|
18
|
+
tag(:input, select_options) + "\n".html_safe
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Rails
|
2
|
+
module HiddenAutocomplete
|
3
|
+
module ActionView
|
4
|
+
module Helpers
|
5
|
+
module UrlHelper
|
6
|
+
mattr_accessor :button_to_generates_button_tag, default: false
|
7
|
+
|
8
|
+
def button_to(name = nil, options = nil, html_options = nil, &block)
|
9
|
+
if block
|
10
|
+
html_options = options
|
11
|
+
options = name
|
12
|
+
end
|
13
|
+
options ||= {}
|
14
|
+
html_options ||= {}
|
15
|
+
html_options = html_options.stringify_keys
|
16
|
+
|
17
|
+
url = options.is_a?(String) ? options : url_for(options)
|
18
|
+
remote = html_options.delete('remote')
|
19
|
+
params = html_options.delete('params')
|
20
|
+
|
21
|
+
method = html_options.delete('method').to_s
|
22
|
+
method_tag = %w[patch put delete].include?(method) ? method_tag(method) : ''.html_safe
|
23
|
+
|
24
|
+
form_method = method == 'get' ? 'get' : 'post'
|
25
|
+
form_options = html_options.delete('form') || {}
|
26
|
+
form_options[:class] ||= html_options.delete('form_class') || 'button_to'
|
27
|
+
form_options[:method] = form_method
|
28
|
+
form_options[:action] = url
|
29
|
+
form_options[:'data-remote'] = true if remote
|
30
|
+
|
31
|
+
request_token_tag = if form_method == 'post'
|
32
|
+
request_method = method.empty? ? 'post' : method
|
33
|
+
token_tag(nil, form_options: { action: url, method: request_method })
|
34
|
+
else
|
35
|
+
''
|
36
|
+
end
|
37
|
+
|
38
|
+
html_options = convert_options_to_data_attributes(options, html_options)
|
39
|
+
html_options['type'] = 'submit'
|
40
|
+
|
41
|
+
button = if block || button_to_generates_button_tag
|
42
|
+
content_tag('button', name || url, html_options, &block)
|
43
|
+
else
|
44
|
+
html_options['value'] = name || url
|
45
|
+
tag('input', html_options)
|
46
|
+
end
|
47
|
+
|
48
|
+
inner_tags = method_tag.safe_concat(button).safe_concat(request_token_tag)
|
49
|
+
if params
|
50
|
+
to_form_params(params).each do |param|
|
51
|
+
inner_tags.safe_concat tag(:input, type: 'hidden', name: param[:name], value: param[:value],
|
52
|
+
autocomplete: 'off')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
content_tag('form', inner_tags, form_options)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def token_tag(token = nil, form_options: {})
|
61
|
+
if token != false && defined?(protect_against_forgery?) && protect_against_forgery?
|
62
|
+
token ||= form_authenticity_token(form_options: form_options)
|
63
|
+
tag(:input, type: 'hidden', name: request_forgery_protection_token.to_s, value: token, autocomplete: 'off')
|
64
|
+
else
|
65
|
+
''
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def method_tag(method)
|
70
|
+
tag('input', type: 'hidden', name: '_method', value: method.to_s, autocomplete: 'off')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require "rails/hidden_autocomplete/engine"
|
2
|
+
require "rails/hidden_autocomplete/action_view/helpers/date_time_selector"
|
3
|
+
require "rails/hidden_autocomplete/action_view/helpers/form_tag_helper"
|
4
|
+
require "rails/hidden_autocomplete/action_view/helpers/tags"
|
5
|
+
require "rails/hidden_autocomplete/action_view/helpers/url_helper"
|
6
|
+
|
7
|
+
module Rails
|
8
|
+
module HiddenAutocomplete
|
9
|
+
end
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-hidden_autocomplete
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Baumann
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-09-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 6.0.3.2
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '6.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 6.0.3.2
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: sqlite3
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
description: rails-hidden_autocomplete is a Rails-modifying Rails Engine to inject
|
48
|
+
the autocomplete="off" attribute into all hidden form inputs generated by Rails.
|
49
|
+
This is necessary because Firefox will randomly overwrite the values of hidden inputs
|
50
|
+
without an autocomplete="off" attribute.
|
51
|
+
email:
|
52
|
+
- ryan@podqueue.fm
|
53
|
+
executables: []
|
54
|
+
extensions: []
|
55
|
+
extra_rdoc_files: []
|
56
|
+
files:
|
57
|
+
- MIT-LICENSE
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- app/assets/config/rails_hidden_autocomplete_manifest.js
|
61
|
+
- config/initializers/rails-hidden_autocomplete.rb
|
62
|
+
- config/routes.rb
|
63
|
+
- lib/rails/hidden_autocomplete.rb
|
64
|
+
- lib/rails/hidden_autocomplete/action_view/helpers/date_time_selector.rb
|
65
|
+
- lib/rails/hidden_autocomplete/action_view/helpers/form_tag_helper.rb
|
66
|
+
- lib/rails/hidden_autocomplete/action_view/helpers/tags.rb
|
67
|
+
- lib/rails/hidden_autocomplete/action_view/helpers/url_helper.rb
|
68
|
+
- lib/rails/hidden_autocomplete/engine.rb
|
69
|
+
- lib/rails/hidden_autocomplete/version.rb
|
70
|
+
- lib/tasks/rails/hidden_autocomplete_tasks.rake
|
71
|
+
homepage: https://github.com/podqueue/rails-hidden_autocomplete
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.7.6.2
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Adds autocomplete="off" to all hidden inputs generated by Rails
|
95
|
+
test_files: []
|