strip_parameters 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/.github/ISSUE_TEMPLATE/bug_report.md +20 -0
- data/.github/ISSUE_TEMPLATE/feature-request.md +18 -0
- data/.github/workflows/rubocop.yml +16 -0
- data/.github/workflows/test.yml +16 -0
- data/.gitignore +6 -0
- data/.overcommit.yml +32 -0
- data/.rubocop.yml +12 -0
- data/.tool-versions +1 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +206 -0
- data/Rakefile +10 -0
- data/bin/integrity +9 -0
- data/bin/rake +27 -0
- data/bin/rubocop +27 -0
- data/bin/standardrb +27 -0
- data/lib/strip_parameters/stripper.rb +69 -0
- data/lib/strip_parameters/version.rb +5 -0
- data/lib/strip_parameters.rb +38 -0
- data/strip_paremeters.gemspec +25 -0
- data/test/controllers/configured_controller_test.rb +17 -0
- data/test/controllers/defaults_controller_test.rb +17 -0
- data/test/support/stripped_app/Rakefile +6 -0
- data/test/support/stripped_app/app/controllers/application_controller.rb +2 -0
- data/test/support/stripped_app/app/controllers/configured_controller.rb +9 -0
- data/test/support/stripped_app/app/controllers/defaults_controller.rb +9 -0
- data/test/support/stripped_app/config/application.rb +56 -0
- data/test/support/stripped_app/config/boot.rb +3 -0
- data/test/support/stripped_app/config/environment.rb +5 -0
- data/test/support/stripped_app/config/routes.rb +6 -0
- data/test/support/stripped_app/log/.keep +0 -0
- data/test/support/stripped_app/tmp/.keep +0 -0
- data/test/test_helper.rb +10 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f13e6bfc81f14243aba3153ed94b687b98ae59632d935b22dee5a5c9b2912cfe
|
4
|
+
data.tar.gz: 8eca6390355940026c9b6df1ff851e7ada11c6b4ef81ab0bcea029b18f3d4674
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 84b839df8f416dc80d9cb65e11e1365d575fe75c23eca571e7d1e09bf34d64eba25a8c36c10c17c4f6cb0c3e05459b279e8343e44a02aca39f1457dd087a37f8
|
7
|
+
data.tar.gz: 1874ed9c892deae6a0b272f6611b59e50273fccefdfea7a0388e61e6529bb751b38f8c3858fc0c8464f6b0b9bfc7e7a365595605aeffa552d790c3dfe83d4a1f
|
@@ -0,0 +1,20 @@
|
|
1
|
+
---
|
2
|
+
name: Bug report
|
3
|
+
about: Create a report for a crash or unexpected behavior.
|
4
|
+
title: ''
|
5
|
+
labels: bug
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
A bug is a crash or incorrect behavior. If you have a debugging or troubleshooting question, please open a discussion
|
11
|
+
|
12
|
+
Ruby version:
|
13
|
+
Rails version:
|
14
|
+
Webpacker version:
|
15
|
+
|
16
|
+
Expected behavior:
|
17
|
+
|
18
|
+
Actual behavior:
|
19
|
+
|
20
|
+
Small, reproducible repo:
|
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
name: Feature request
|
3
|
+
about: Create a request for new functionality
|
4
|
+
title: ''
|
5
|
+
labels: enhancement
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
A feature request is describes a suggested improvement. If you have a debugging or troubleshooting question, please open a discussion
|
11
|
+
|
12
|
+
Ruby version:
|
13
|
+
Rails version:
|
14
|
+
Webpacker version:
|
15
|
+
|
16
|
+
Desired behavior:
|
17
|
+
|
18
|
+
Actual behavior:
|
@@ -0,0 +1,16 @@
|
|
1
|
+
name: Rubocop
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
rubocop:
|
7
|
+
name: Rubocop
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v2
|
11
|
+
- uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: "3.0"
|
14
|
+
bundler-cache: true
|
15
|
+
- name: Ruby linter
|
16
|
+
run: bundle exec rubocop
|
@@ -0,0 +1,16 @@
|
|
1
|
+
name: Ruby tests
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
name: Ruby tests
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v2
|
11
|
+
- uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: "3.0"
|
14
|
+
bundler-cache: true
|
15
|
+
- name: Ruby tests
|
16
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.overcommit.yml
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Overcommit hooks run automatically on certain git operations, like "git commit".
|
2
|
+
# For a complete list of options that you can use to customize hooks, see:
|
3
|
+
# https://github.com/sds/overcommit
|
4
|
+
|
5
|
+
gemfile: false
|
6
|
+
verify_signatures: false
|
7
|
+
|
8
|
+
PreCommit:
|
9
|
+
BundleCheck:
|
10
|
+
enabled: true
|
11
|
+
|
12
|
+
FixMe:
|
13
|
+
enabled: true
|
14
|
+
keywords: ["FIXME"]
|
15
|
+
exclude:
|
16
|
+
- .overcommit.yml
|
17
|
+
|
18
|
+
LocalPathsInGemfile:
|
19
|
+
enabled: true
|
20
|
+
|
21
|
+
RuboCop:
|
22
|
+
enabled: true
|
23
|
+
required_executable: bundle
|
24
|
+
command: ["bundle", "exec", "rubocop"]
|
25
|
+
on_warn: fail
|
26
|
+
|
27
|
+
YamlSyntax:
|
28
|
+
enabled: true
|
29
|
+
|
30
|
+
PostCheckout:
|
31
|
+
ALL:
|
32
|
+
quiet: true
|
data/.rubocop.yml
ADDED
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.1.2
|
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gemspec
|
6
|
+
|
7
|
+
gem "rake", ">= 13.0.6", require: false
|
8
|
+
gem "rails", ">= 7.0.0", require: false
|
9
|
+
gem "standard", ">=1.12.1", require: false
|
10
|
+
gem "rubocop-performance", ">=1.13.3", require: false
|
11
|
+
gem "overcommit", ">=0.59.1", require: false
|
12
|
+
gem "debug", ">=1.5.0", require: false
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
strip_parameters (0.1.0)
|
5
|
+
actionpack (>= 4.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actioncable (7.0.3)
|
11
|
+
actionpack (= 7.0.3)
|
12
|
+
activesupport (= 7.0.3)
|
13
|
+
nio4r (~> 2.0)
|
14
|
+
websocket-driver (>= 0.6.1)
|
15
|
+
actionmailbox (7.0.3)
|
16
|
+
actionpack (= 7.0.3)
|
17
|
+
activejob (= 7.0.3)
|
18
|
+
activerecord (= 7.0.3)
|
19
|
+
activestorage (= 7.0.3)
|
20
|
+
activesupport (= 7.0.3)
|
21
|
+
mail (>= 2.7.1)
|
22
|
+
net-imap
|
23
|
+
net-pop
|
24
|
+
net-smtp
|
25
|
+
actionmailer (7.0.3)
|
26
|
+
actionpack (= 7.0.3)
|
27
|
+
actionview (= 7.0.3)
|
28
|
+
activejob (= 7.0.3)
|
29
|
+
activesupport (= 7.0.3)
|
30
|
+
mail (~> 2.5, >= 2.5.4)
|
31
|
+
net-imap
|
32
|
+
net-pop
|
33
|
+
net-smtp
|
34
|
+
rails-dom-testing (~> 2.0)
|
35
|
+
actionpack (7.0.3)
|
36
|
+
actionview (= 7.0.3)
|
37
|
+
activesupport (= 7.0.3)
|
38
|
+
rack (~> 2.0, >= 2.2.0)
|
39
|
+
rack-test (>= 0.6.3)
|
40
|
+
rails-dom-testing (~> 2.0)
|
41
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
42
|
+
actiontext (7.0.3)
|
43
|
+
actionpack (= 7.0.3)
|
44
|
+
activerecord (= 7.0.3)
|
45
|
+
activestorage (= 7.0.3)
|
46
|
+
activesupport (= 7.0.3)
|
47
|
+
globalid (>= 0.6.0)
|
48
|
+
nokogiri (>= 1.8.5)
|
49
|
+
actionview (7.0.3)
|
50
|
+
activesupport (= 7.0.3)
|
51
|
+
builder (~> 3.1)
|
52
|
+
erubi (~> 1.4)
|
53
|
+
rails-dom-testing (~> 2.0)
|
54
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
55
|
+
activejob (7.0.3)
|
56
|
+
activesupport (= 7.0.3)
|
57
|
+
globalid (>= 0.3.6)
|
58
|
+
activemodel (7.0.3)
|
59
|
+
activesupport (= 7.0.3)
|
60
|
+
activerecord (7.0.3)
|
61
|
+
activemodel (= 7.0.3)
|
62
|
+
activesupport (= 7.0.3)
|
63
|
+
activestorage (7.0.3)
|
64
|
+
actionpack (= 7.0.3)
|
65
|
+
activejob (= 7.0.3)
|
66
|
+
activerecord (= 7.0.3)
|
67
|
+
activesupport (= 7.0.3)
|
68
|
+
marcel (~> 1.0)
|
69
|
+
mini_mime (>= 1.1.0)
|
70
|
+
activesupport (7.0.3)
|
71
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
72
|
+
i18n (>= 1.6, < 2)
|
73
|
+
minitest (>= 5.1)
|
74
|
+
tzinfo (~> 2.0)
|
75
|
+
ast (2.4.2)
|
76
|
+
builder (3.2.4)
|
77
|
+
childprocess (4.1.0)
|
78
|
+
concurrent-ruby (1.1.10)
|
79
|
+
crass (1.0.6)
|
80
|
+
debug (1.5.0)
|
81
|
+
irb (>= 1.3.6)
|
82
|
+
reline (>= 0.2.7)
|
83
|
+
digest (3.1.0)
|
84
|
+
erubi (1.10.0)
|
85
|
+
globalid (1.0.0)
|
86
|
+
activesupport (>= 5.0)
|
87
|
+
i18n (1.10.0)
|
88
|
+
concurrent-ruby (~> 1.0)
|
89
|
+
iniparse (1.5.0)
|
90
|
+
io-console (0.5.11)
|
91
|
+
irb (1.4.1)
|
92
|
+
reline (>= 0.3.0)
|
93
|
+
loofah (2.18.0)
|
94
|
+
crass (~> 1.0.2)
|
95
|
+
nokogiri (>= 1.5.9)
|
96
|
+
mail (2.7.1)
|
97
|
+
mini_mime (>= 0.1.1)
|
98
|
+
marcel (1.0.2)
|
99
|
+
method_source (1.0.0)
|
100
|
+
mini_mime (1.1.2)
|
101
|
+
mini_portile2 (2.8.0)
|
102
|
+
minitest (5.15.0)
|
103
|
+
net-imap (0.2.3)
|
104
|
+
digest
|
105
|
+
net-protocol
|
106
|
+
strscan
|
107
|
+
net-pop (0.1.1)
|
108
|
+
digest
|
109
|
+
net-protocol
|
110
|
+
timeout
|
111
|
+
net-protocol (0.1.3)
|
112
|
+
timeout
|
113
|
+
net-smtp (0.3.1)
|
114
|
+
digest
|
115
|
+
net-protocol
|
116
|
+
timeout
|
117
|
+
nio4r (2.5.8)
|
118
|
+
nokogiri (1.13.6)
|
119
|
+
mini_portile2 (~> 2.8.0)
|
120
|
+
racc (~> 1.4)
|
121
|
+
overcommit (0.59.1)
|
122
|
+
childprocess (>= 0.6.3, < 5)
|
123
|
+
iniparse (~> 1.4)
|
124
|
+
rexml (~> 3.2)
|
125
|
+
parallel (1.22.1)
|
126
|
+
parser (3.1.2.0)
|
127
|
+
ast (~> 2.4.1)
|
128
|
+
racc (1.6.0)
|
129
|
+
rack (2.2.3.1)
|
130
|
+
rack-test (1.1.0)
|
131
|
+
rack (>= 1.0, < 3)
|
132
|
+
rails (7.0.3)
|
133
|
+
actioncable (= 7.0.3)
|
134
|
+
actionmailbox (= 7.0.3)
|
135
|
+
actionmailer (= 7.0.3)
|
136
|
+
actionpack (= 7.0.3)
|
137
|
+
actiontext (= 7.0.3)
|
138
|
+
actionview (= 7.0.3)
|
139
|
+
activejob (= 7.0.3)
|
140
|
+
activemodel (= 7.0.3)
|
141
|
+
activerecord (= 7.0.3)
|
142
|
+
activestorage (= 7.0.3)
|
143
|
+
activesupport (= 7.0.3)
|
144
|
+
bundler (>= 1.15.0)
|
145
|
+
railties (= 7.0.3)
|
146
|
+
rails-dom-testing (2.0.3)
|
147
|
+
activesupport (>= 4.2.0)
|
148
|
+
nokogiri (>= 1.6)
|
149
|
+
rails-html-sanitizer (1.4.2)
|
150
|
+
loofah (~> 2.3)
|
151
|
+
railties (7.0.3)
|
152
|
+
actionpack (= 7.0.3)
|
153
|
+
activesupport (= 7.0.3)
|
154
|
+
method_source
|
155
|
+
rake (>= 12.2)
|
156
|
+
thor (~> 1.0)
|
157
|
+
zeitwerk (~> 2.5)
|
158
|
+
rainbow (3.1.1)
|
159
|
+
rake (13.0.6)
|
160
|
+
regexp_parser (2.5.0)
|
161
|
+
reline (0.3.1)
|
162
|
+
io-console (~> 0.5)
|
163
|
+
rexml (3.2.5)
|
164
|
+
rubocop (1.29.1)
|
165
|
+
parallel (~> 1.10)
|
166
|
+
parser (>= 3.1.0.0)
|
167
|
+
rainbow (>= 2.2.2, < 4.0)
|
168
|
+
regexp_parser (>= 1.8, < 3.0)
|
169
|
+
rexml (>= 3.2.5, < 4.0)
|
170
|
+
rubocop-ast (>= 1.17.0, < 2.0)
|
171
|
+
ruby-progressbar (~> 1.7)
|
172
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
173
|
+
rubocop-ast (1.18.0)
|
174
|
+
parser (>= 3.1.1.0)
|
175
|
+
rubocop-performance (1.13.3)
|
176
|
+
rubocop (>= 1.7.0, < 2.0)
|
177
|
+
rubocop-ast (>= 0.4.0)
|
178
|
+
ruby-progressbar (1.11.0)
|
179
|
+
standard (1.12.1)
|
180
|
+
rubocop (= 1.29.1)
|
181
|
+
rubocop-performance (= 1.13.3)
|
182
|
+
strscan (3.0.3)
|
183
|
+
thor (1.2.1)
|
184
|
+
timeout (0.3.0)
|
185
|
+
tzinfo (2.0.4)
|
186
|
+
concurrent-ruby (~> 1.0)
|
187
|
+
unicode-display_width (2.1.0)
|
188
|
+
websocket-driver (0.7.5)
|
189
|
+
websocket-extensions (>= 0.1.0)
|
190
|
+
websocket-extensions (0.1.5)
|
191
|
+
zeitwerk (2.5.4)
|
192
|
+
|
193
|
+
PLATFORMS
|
194
|
+
ruby
|
195
|
+
|
196
|
+
DEPENDENCIES
|
197
|
+
debug (>= 1.5.0)
|
198
|
+
overcommit (>= 0.59.1)
|
199
|
+
rails (>= 7.0.0)
|
200
|
+
rake (>= 13.0.6)
|
201
|
+
rubocop-performance (>= 1.13.3)
|
202
|
+
standard (>= 1.12.1)
|
203
|
+
strip_parameters!
|
204
|
+
|
205
|
+
BUNDLED WITH
|
206
|
+
2.3.15
|
data/Rakefile
ADDED
data/bin/integrity
ADDED
data/bin/rake
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rake' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
12
|
+
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
14
|
+
|
15
|
+
if File.file?(bundle_binstub)
|
16
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
17
|
+
load(bundle_binstub)
|
18
|
+
else
|
19
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
20
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require "rubygems"
|
25
|
+
require "bundler/setup"
|
26
|
+
|
27
|
+
load Gem.bin_path("rake", "rake")
|
data/bin/rubocop
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'rubocop' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
12
|
+
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
14
|
+
|
15
|
+
if File.file?(bundle_binstub)
|
16
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
17
|
+
load(bundle_binstub)
|
18
|
+
else
|
19
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
20
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require "rubygems"
|
25
|
+
require "bundler/setup"
|
26
|
+
|
27
|
+
load Gem.bin_path("rubocop", "rubocop")
|
data/bin/standardrb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'standardrb' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
|
12
|
+
|
13
|
+
bundle_binstub = File.expand_path("bundle", __dir__)
|
14
|
+
|
15
|
+
if File.file?(bundle_binstub)
|
16
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
17
|
+
load(bundle_binstub)
|
18
|
+
else
|
19
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
20
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require "rubygems"
|
25
|
+
require "bundler/setup"
|
26
|
+
|
27
|
+
load Gem.bin_path("standard", "standardrb")
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module StripParameters
|
4
|
+
# Singleton that does the actual stripping.
|
5
|
+
class Stripper
|
6
|
+
VALID_OPTIONS = %i[only except if unless allow_empty collapse_spaces replace_newlines regex].freeze
|
7
|
+
|
8
|
+
# Unicode invisible and whitespace characters. The POSIX character class
|
9
|
+
# [:space:] corresponds to the Unicode class Z ("separator"). We also
|
10
|
+
# include the following characters from Unicode class C ("control"), which
|
11
|
+
# are spaces or invisible characters that make no sense at the start or end
|
12
|
+
# of a string:
|
13
|
+
# U+180E MONGOLIAN VOWEL SEPARATOR
|
14
|
+
# U+200B ZERO WIDTH SPACE
|
15
|
+
# U+200C ZERO WIDTH NON-JOINER
|
16
|
+
# U+200D ZERO WIDTH JOINER
|
17
|
+
# U+2060 WORD JOINER
|
18
|
+
# U+FEFF ZERO WIDTH NO-BREAK SPACE
|
19
|
+
MULTIBYTE_WHITE = "\u180E\u200B\u200C\u200D\u2060\uFEFF"
|
20
|
+
MULTIBYTE_SPACE = /[[:space:]#{MULTIBYTE_WHITE}]/
|
21
|
+
MULTIBYTE_SPACE_REGEX = /\A#{MULTIBYTE_SPACE}+|#{MULTIBYTE_SPACE}+\z/
|
22
|
+
MULTIBYTE_BLANK = /[[:blank:]#{MULTIBYTE_WHITE}]/
|
23
|
+
MULTIBYTE_BLANK_REGEX = /#{MULTIBYTE_BLANK}+/
|
24
|
+
|
25
|
+
def self.strip(paramters, **options)
|
26
|
+
paramters.transform_values! do |value|
|
27
|
+
if value.is_a?(ActionController::Parameters)
|
28
|
+
strip(value, **options)
|
29
|
+
else
|
30
|
+
next value if !value.is_a?(String) || value.frozen?
|
31
|
+
|
32
|
+
process_string(value, **options)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.process_string(value, regex: nil, replace_newlines: false, collapse_spaces: false, allow_empty: false)
|
38
|
+
value.gsub!(regex, "") if regex
|
39
|
+
value.gsub!(/[\r\n]+/, " ") if replace_newlines
|
40
|
+
collapse_inner_string_spaces(value) if collapse_spaces
|
41
|
+
strip_string(value)
|
42
|
+
|
43
|
+
value if value != "" || allow_empty
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.strip_string(value)
|
47
|
+
if Encoding.compatible?(value, MULTIBYTE_SPACE)
|
48
|
+
value.gsub!(MULTIBYTE_SPACE_REGEX, "")
|
49
|
+
else
|
50
|
+
value.strip!
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.collapse_inner_string_spaces(value)
|
55
|
+
if Encoding.compatible?(value, MULTIBYTE_BLANK)
|
56
|
+
value.gsub!(MULTIBYTE_BLANK_REGEX, " ")
|
57
|
+
else
|
58
|
+
value.squeeze!(" ")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.validate_options(options)
|
63
|
+
keys = options.keys
|
64
|
+
return unless (keys - VALID_OPTIONS).any?
|
65
|
+
|
66
|
+
raise ArgumentError, "Unexpected options #{options.keys.inspect}. Valid options are #{VALID_OPTIONS}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "strip_parameters/stripper"
|
4
|
+
|
5
|
+
# Registers before_action filter and sets configuration options.
|
6
|
+
module StripParameters
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do |base|
|
10
|
+
base.class_attribute(:strip_parameters_options, default: {})
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
# This method can be used in actions without setting up filter.
|
16
|
+
# See class method StripParameters.strip_parameters
|
17
|
+
def strip_parameters(**options)
|
18
|
+
Stripper.strip(params, **strip_parameters_options.merge(options))
|
19
|
+
end
|
20
|
+
|
21
|
+
class_methods do
|
22
|
+
# Sets configuration options and register strip_parameters filter.
|
23
|
+
#
|
24
|
+
# @param [Regexp] regex - expression to replace in parametes values.
|
25
|
+
# @param [Boolean] replace_newlines - replace newlines with spaces.
|
26
|
+
# @param [Boolean] collapse_spaces - replaces multiple spaces with one.
|
27
|
+
# @param [Boolean] allow_empty - keeps empty strings.
|
28
|
+
#
|
29
|
+
# @return [nil]
|
30
|
+
#
|
31
|
+
def strip_parameters(**options)
|
32
|
+
Stripper.validate_options(options)
|
33
|
+
self.strip_parameters_options = options.slice(*%i[allow_empty collapse_spaces replace_newlines regex])
|
34
|
+
# TODO: unregister previously registered callback if any
|
35
|
+
before_action(:strip_parameters, options.slice(*%i[only except if unless]))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push(File.expand_path("lib", __dir__))
|
4
|
+
require "strip_parameters/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "strip_parameters"
|
8
|
+
s.version = StripParameters::VERSION
|
9
|
+
s.authors = ["Anton Topchii"]
|
10
|
+
s.email = ["player1@infinitevoid.net"]
|
11
|
+
s.summary = 'Use strip_attributes to make empty parameters to be nils and forget about ".present?"'
|
12
|
+
s.homepage = "https://github.com/crawler/strip_parameters"
|
13
|
+
s.license = "MIT"
|
14
|
+
|
15
|
+
s.metadata = {
|
16
|
+
"source_code_uri" => "https://github.com/crawler/strip_parameters/tree/v#{StripParameters::VERSION}",
|
17
|
+
"rubygems_mfa_required" => "true"
|
18
|
+
}
|
19
|
+
|
20
|
+
s.required_ruby_version = ">= 2.4.0"
|
21
|
+
|
22
|
+
s.add_runtime_dependency "actionpack", ">= 4.0"
|
23
|
+
s.files = `git ls-files`.split("\n")
|
24
|
+
s.test_files = `git ls-files -- test/*`.split("\n")
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
class ConfiguredControllerTest < ActionDispatch::IntegrationTest
|
6
|
+
def test_strip_parameters
|
7
|
+
post "/configured", params: SAME_PARAMS
|
8
|
+
|
9
|
+
assert_equal("John Doe", controller.params[:name])
|
10
|
+
assert_equal("", controller.params[:email])
|
11
|
+
assert_equal("text with inner things", controller.params[:message])
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.app
|
15
|
+
Rails.application
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "test_helper"
|
4
|
+
|
5
|
+
class DefaultsControllerTest < ActionDispatch::IntegrationTest
|
6
|
+
def test_strip_parameters
|
7
|
+
post "/defaults", params: SAME_PARAMS
|
8
|
+
|
9
|
+
assert_equal("John Doe", controller.params[:name])
|
10
|
+
assert_nil(controller.params[:email])
|
11
|
+
assert_equal("text \nwith inner things 2", controller.params[:message])
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.app
|
15
|
+
Rails.application
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ConfiguredController < ApplicationController
|
4
|
+
include StripParameters
|
5
|
+
strip_parameters(regex: /[0-9]/, replace_newlines: true, collapse_spaces: true, allow_empty: true)
|
6
|
+
|
7
|
+
def create
|
8
|
+
end
|
9
|
+
end # class ConfiguredController
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "boot"
|
4
|
+
|
5
|
+
require "rails"
|
6
|
+
# Pick the frameworks you want:
|
7
|
+
# require "active_model/railtie"
|
8
|
+
# require "active_job/railtie"
|
9
|
+
# require "active_record/railtie"
|
10
|
+
# require "active_storage/engine"
|
11
|
+
require "action_controller/railtie"
|
12
|
+
# require "action_mailer/railtie"
|
13
|
+
# require "action_mailbox/engine"
|
14
|
+
# require "action_text/engine"
|
15
|
+
# require "action_view/railtie"
|
16
|
+
# require "action_cable/engine"
|
17
|
+
# require "rails/test_unit/railtie"
|
18
|
+
|
19
|
+
# Require the gems listed in Gemfile, including any gems
|
20
|
+
# you've limited to :test, :development, or :production.
|
21
|
+
Bundler.require(*Rails.groups)
|
22
|
+
|
23
|
+
module StrippedApp
|
24
|
+
class Application < Rails::Application
|
25
|
+
config.load_defaults 7.0
|
26
|
+
config.log_level = :debug
|
27
|
+
config.root = Pathname.new(__dir__).parent
|
28
|
+
|
29
|
+
# Settings specified here will take precedence over those in config/application.rb.
|
30
|
+
|
31
|
+
# Turn false under Spring and add config.action_view.cache_template_loading = true.
|
32
|
+
config.cache_classes = true
|
33
|
+
|
34
|
+
# Eager loading loads your whole application. When running a single test locally,
|
35
|
+
# this probably isn't necessary. It's a good idea to do in a continuous integration
|
36
|
+
# system, or in some way before deploying your code.
|
37
|
+
config.eager_load = ENV["CI"].present?
|
38
|
+
|
39
|
+
# Show full error reports and disable caching.
|
40
|
+
config.consider_all_requests_local = true
|
41
|
+
config.action_controller.perform_caching = false
|
42
|
+
config.cache_store = :null_store
|
43
|
+
|
44
|
+
# Raise exceptions instead of rendering exception templates.
|
45
|
+
config.action_dispatch.show_exceptions = false
|
46
|
+
|
47
|
+
# Disable request forgery protection in test environment.
|
48
|
+
config.action_controller.allow_forgery_protection = false
|
49
|
+
|
50
|
+
# Print deprecation notices to the stderr.
|
51
|
+
config.active_support.deprecation = :stderr
|
52
|
+
|
53
|
+
# Raise exceptions for disallowed deprecations.
|
54
|
+
config.active_support.disallowed_deprecation = :raise
|
55
|
+
end
|
56
|
+
end
|
File without changes
|
File without changes
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
ENV["RAILS_ENV"] = "test"
|
4
|
+
require_relative "support/stripped_app/config/environment"
|
5
|
+
require "rails/test_help"
|
6
|
+
tests_path = Pathname.new(__dir__)
|
7
|
+
$LOAD_PATH.push(tests_path.to_s)
|
8
|
+
require "debug"
|
9
|
+
|
10
|
+
SAME_PARAMS = {name: " John Doe\r\n", email: "\r\n \n", message: "text \nwith inner things 2"}
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: strip_parameters
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anton Topchii
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-06-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- player1@infinitevoid.net
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
35
|
+
- ".github/ISSUE_TEMPLATE/feature-request.md"
|
36
|
+
- ".github/workflows/rubocop.yml"
|
37
|
+
- ".github/workflows/test.yml"
|
38
|
+
- ".gitignore"
|
39
|
+
- ".overcommit.yml"
|
40
|
+
- ".rubocop.yml"
|
41
|
+
- ".tool-versions"
|
42
|
+
- Gemfile
|
43
|
+
- Gemfile.lock
|
44
|
+
- Rakefile
|
45
|
+
- bin/integrity
|
46
|
+
- bin/rake
|
47
|
+
- bin/rubocop
|
48
|
+
- bin/standardrb
|
49
|
+
- lib/strip_parameters.rb
|
50
|
+
- lib/strip_parameters/stripper.rb
|
51
|
+
- lib/strip_parameters/version.rb
|
52
|
+
- strip_paremeters.gemspec
|
53
|
+
- test/controllers/configured_controller_test.rb
|
54
|
+
- test/controllers/defaults_controller_test.rb
|
55
|
+
- test/support/stripped_app/Rakefile
|
56
|
+
- test/support/stripped_app/app/controllers/application_controller.rb
|
57
|
+
- test/support/stripped_app/app/controllers/configured_controller.rb
|
58
|
+
- test/support/stripped_app/app/controllers/defaults_controller.rb
|
59
|
+
- test/support/stripped_app/config/application.rb
|
60
|
+
- test/support/stripped_app/config/boot.rb
|
61
|
+
- test/support/stripped_app/config/environment.rb
|
62
|
+
- test/support/stripped_app/config/routes.rb
|
63
|
+
- test/support/stripped_app/log/.keep
|
64
|
+
- test/support/stripped_app/tmp/.keep
|
65
|
+
- test/test_helper.rb
|
66
|
+
homepage: https://github.com/crawler/strip_parameters
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata:
|
70
|
+
source_code_uri: https://github.com/crawler/strip_parameters/tree/v0.1.0
|
71
|
+
rubygems_mfa_required: 'true'
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 2.4.0
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubygems_version: 3.3.7
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Use strip_attributes to make empty parameters to be nils and forget about
|
91
|
+
".present?"
|
92
|
+
test_files:
|
93
|
+
- test/controllers/configured_controller_test.rb
|
94
|
+
- test/controllers/defaults_controller_test.rb
|
95
|
+
- test/support/stripped_app/Rakefile
|
96
|
+
- test/support/stripped_app/app/controllers/application_controller.rb
|
97
|
+
- test/support/stripped_app/app/controllers/configured_controller.rb
|
98
|
+
- test/support/stripped_app/app/controllers/defaults_controller.rb
|
99
|
+
- test/support/stripped_app/config/application.rb
|
100
|
+
- test/support/stripped_app/config/boot.rb
|
101
|
+
- test/support/stripped_app/config/environment.rb
|
102
|
+
- test/support/stripped_app/config/routes.rb
|
103
|
+
- test/support/stripped_app/log/.keep
|
104
|
+
- test/support/stripped_app/tmp/.keep
|
105
|
+
- test/test_helper.rb
|