strelka 0.18.0 → 0.19.0
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
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/History.rdoc +24 -0
- data/IDEAS.rdoc +0 -1
- data/README.rdoc +12 -6
- data/Rakefile +4 -94
- data/lib/strelka.rb +1 -1
- data/lib/strelka/app.rb +2 -3
- data/lib/strelka/app/parameters.rb +3 -12
- data/lib/strelka/app/restresources.rb +0 -3
- data/lib/strelka/cookie.rb +1 -1
- data/lib/strelka/mixins.rb +1 -1
- data/lib/strelka/multirunner.rb +34 -11
- data/lib/strelka/paramvalidator.rb +22 -45
- data/lib/strelka/session/default.rb +1 -1
- data/spec/strelka/app/parameters_spec.rb +1 -27
- data/spec/strelka/app_spec.rb +0 -12
- data/spec/strelka/mixins_spec.rb +0 -10
- data/spec/strelka/paramvalidator_spec.rb +4 -54
- metadata +51 -143
- metadata.gz.sig +0 -0
- data/.gemtest +0 -0
- data/ChangeLog +0 -3824
- data/MILESTONES.rdoc +0 -24
- data/Manifest.txt +0 -144
- data/contrib/hoetemplate/History.rdoc.erb +0 -4
- data/contrib/hoetemplate/Manifest.txt.erb +0 -8
- data/contrib/hoetemplate/README.rdoc.erb +0 -35
- data/contrib/hoetemplate/Rakefile.erb +0 -24
- data/contrib/hoetemplate/data/project/apps/file_name_app +0 -37
- data/contrib/hoetemplate/data/project/templates/layout.tmpl.erb +0 -13
- data/contrib/hoetemplate/data/project/templates/top.tmpl.erb +0 -8
- data/contrib/hoetemplate/lib/file_name.rb.erb +0 -15
- data/contrib/hoetemplate/spec/file_name_spec.rb.erb +0 -21
- data/contrib/strelka-dogs/doggie6.svg +0 -271
- data/contrib/strelka-dogs/doggie7.svg +0 -49
- data/examples/Procfile +0 -9
- data/examples/apps/auth-demo +0 -29
- data/examples/apps/auth-demo2 +0 -37
- data/examples/apps/hello-world +0 -30
- data/examples/apps/sessions-demo +0 -42
- data/examples/apps/upload-demo +0 -74
- data/examples/apps/ws-chat +0 -69
- data/examples/apps/ws-echo +0 -61
- data/examples/config.yml +0 -33
- data/examples/gen-config.rb +0 -52
- data/examples/static/examples.css +0 -4
- data/examples/static/examples.html +0 -33
- data/examples/strelka.conf.example +0 -51
- data/examples/templates/auth-form.tmpl +0 -14
- data/examples/templates/auth-success.tmpl +0 -5
- data/examples/templates/layout.tmpl +0 -31
- data/examples/templates/upload-form.tmpl +0 -17
- data/examples/templates/upload-success.tmpl +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a9926577075cbf009622a30ab13dc4f1fe38c4ba943419c318359d6648a58ba
|
4
|
+
data.tar.gz: 5c19c5a7b328e6cedbba07107a3c732e62e62aa71d0e48fb6b8e5efea3b40ca9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f44a6a2c1be7c96a96cb04111ff914c4022bdf52df94df541b183ce0150222b51d8cd21dedf60cb697fcfddb5c2a66dd339e4dc8caf1f862afa2e1c8bb313f6
|
7
|
+
data.tar.gz: 2e92f0355c0858e750bb0bbc5dfa8f3eb91103bf7632ba53bbeb7a671523bd6c0a659f2deadfb05be91d35efcd7e2a8fd603654e836fa82b47020ad43ad18192
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/History.rdoc
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
= Release History for strelka
|
2
|
+
|
3
|
+
---
|
4
|
+
|
5
|
+
== v0.19.0 [2020-02-05] Mahlon E. Smith <mahlon@martini.nu>
|
6
|
+
|
7
|
+
Bugfixes:
|
8
|
+
|
9
|
+
- Separate reaping from signal sending (FreeBSD)
|
10
|
+
|
11
|
+
Improvements:
|
12
|
+
|
13
|
+
- Default devmode to false, requiring it to be explicitly enabled.
|
14
|
+
- Remove untainting in preparation for Ruby 3.
|
15
|
+
|
16
|
+
|
17
|
+
== v0.18.0 [2019-09-25] Mahlon E. Smith <mahlon@martini.nu>
|
18
|
+
|
19
|
+
Bugfixes:
|
20
|
+
|
21
|
+
- Add an optional hook to perform arbitrary actions before forking.
|
22
|
+
- Make the signal handling for running multiple handlers less naive.
|
23
|
+
|
24
|
+
|
1
25
|
== v0.17.0 [2019-09-18] Mahlon E. Smith <mahlon@martini.nu>
|
2
26
|
|
3
27
|
Enhancements:
|
data/IDEAS.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
= Strelka (Стрелка)
|
2
2
|
|
3
|
-
home
|
4
|
-
code
|
5
|
-
github
|
6
|
-
docs
|
3
|
+
home:: https://hg.sr.ht/~ged/Strelka
|
4
|
+
code:: https://hg.sr.ht/~ged/Strelka/browse
|
5
|
+
github:: https://github.com/ged/strelka
|
6
|
+
docs:: http://deveiate.org/code/strelka
|
7
7
|
|
8
8
|
|
9
9
|
== Description
|
@@ -197,7 +197,7 @@ Support for sending partial responses via the Chunked encoding.
|
|
197
197
|
== Contributing
|
198
198
|
|
199
199
|
You can check out the current development source with Mercurial via its
|
200
|
-
{project page}[http://bitbucket.org/ged/Strelka]. Or if you prefer Git, via
|
200
|
+
{project page}[http://bitbucket.org/ged/Strelka]. Or if you prefer Git, via
|
201
201
|
{its Github mirror}[https://github.com/ged/strelka].
|
202
202
|
|
203
203
|
After checking out the source, run:
|
@@ -208,9 +208,15 @@ This task will install any missing dependencies, run the tests/specs,
|
|
208
208
|
and generate the API documentation.
|
209
209
|
|
210
210
|
|
211
|
+
== Authors
|
212
|
+
|
213
|
+
- Mahlon E. Smith <mahlon@martini.nu>
|
214
|
+
- Michael Granger <ged@faeriemud.org>
|
215
|
+
|
216
|
+
|
211
217
|
== License
|
212
218
|
|
213
|
-
Copyright (c) 2011-
|
219
|
+
Copyright (c) 2011-2020, Michael Granger and Mahlon E. Smith
|
214
220
|
All rights reserved.
|
215
221
|
|
216
222
|
Redistribution and use in source and binary forms, with or without
|
data/Rakefile
CHANGED
@@ -1,98 +1,8 @@
|
|
1
|
-
#!/usr/bin/env rake
|
1
|
+
#!/usr/bin/env ruby -S rake
|
2
2
|
|
3
|
-
require 'rake/
|
3
|
+
require 'rake/deveiate'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
rescue LoadError
|
8
|
-
abort "This Rakefile requires 'hoe' (gem install hoe)"
|
5
|
+
Rake::DevEiate.setup( 'strelka' ) do |project|
|
6
|
+
project.publish_to = 'deveiate:/usr/local/www/public/code'
|
9
7
|
end
|
10
8
|
|
11
|
-
GEMSPEC = 'strelka.gemspec'
|
12
|
-
|
13
|
-
Hoe.plugin :mercurial
|
14
|
-
Hoe.plugin :signing
|
15
|
-
Hoe.plugin :deveiate
|
16
|
-
|
17
|
-
Hoe.plugins.delete :rubyforge
|
18
|
-
|
19
|
-
hoespec = Hoe.spec( 'strelka' ) do
|
20
|
-
self.readme_file = 'README.rdoc'
|
21
|
-
self.history_file = 'History.rdoc'
|
22
|
-
self.extra_rdoc_files = FileList[ '*.rdoc' ]
|
23
|
-
self.license "BSD"
|
24
|
-
|
25
|
-
self.developer 'Mahlon E. Smith', 'mahlon@martini.nu'
|
26
|
-
self.developer 'Michael Granger', 'ged@FaerieMUD.org'
|
27
|
-
|
28
|
-
self.dependency 'configurability', '~> 3.1'
|
29
|
-
self.dependency 'foreman', '~> 0.62'
|
30
|
-
self.dependency 'highline', '~> 1.6'
|
31
|
-
self.dependency 'inversion', '~> 1.0'
|
32
|
-
self.dependency 'loggability', '~> 0.9'
|
33
|
-
self.dependency 'mongrel2', '~> 0.53'
|
34
|
-
self.dependency 'pluggability', '~> 0.4'
|
35
|
-
self.dependency 'sysexits', '~> 1.1'
|
36
|
-
self.dependency 'uuidtools', '~> 2.1'
|
37
|
-
self.dependency 'safe_yaml', '~> 1.0'
|
38
|
-
self.dependency 'gli', '~> 2.14'
|
39
|
-
|
40
|
-
self.dependency 'hoe-deveiate', '~> 0.6', :developer
|
41
|
-
self.dependency 'rspec', '~> 3.0', :developer
|
42
|
-
self.dependency 'simplecov', '~> 0.7', :developer
|
43
|
-
self.dependency 'rdoc-generator-fivefish', '~> 0.1', :developer
|
44
|
-
|
45
|
-
self.require_ruby_version( '>=2.2.0' )
|
46
|
-
self.hg_sign_tags = true if self.respond_to?( :hg_sign_tags= )
|
47
|
-
self.check_history_on_release = true if self.respond_to?( :check_history_on_release= )
|
48
|
-
self.rdoc_locations << "deveiate:/usr/local/www/public/code/#{remote_rdoc_dir}"
|
49
|
-
end
|
50
|
-
|
51
|
-
ENV['VERSION'] ||= hoespec.spec.version.to_s
|
52
|
-
|
53
|
-
# Ensure the specs pass before checking in
|
54
|
-
task 'hg:precheckin' => [:check_history, :check_manifest, :spec]
|
55
|
-
|
56
|
-
if Rake::Task.task_defined?( '.gemtest' )
|
57
|
-
Rake::Task['.gemtest'].clear
|
58
|
-
task '.gemtest' do
|
59
|
-
$stderr.puts "Not including a .gemtest until I'm confident the test suite is idempotent."
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
desc "Build a coverage report"
|
64
|
-
task :coverage do
|
65
|
-
ENV["COVERAGE"] = 'yes'
|
66
|
-
Rake::Task[:spec].invoke
|
67
|
-
end
|
68
|
-
|
69
|
-
|
70
|
-
# Use the fivefish formatter for docs generated from development checkout
|
71
|
-
if File.directory?( '.hg' )
|
72
|
-
require 'rdoc/task'
|
73
|
-
|
74
|
-
Rake::Task[ 'docs' ].clear
|
75
|
-
RDoc::Task.new( 'docs' ) do |rdoc|
|
76
|
-
rdoc.main = "README.rdoc"
|
77
|
-
rdoc.rdoc_files.include( "*.rdoc", "ChangeLog", "lib/**/*.rb" )
|
78
|
-
rdoc.generator = :fivefish
|
79
|
-
rdoc.title = "Strelka: A Ruby Web Framework"
|
80
|
-
rdoc.rdoc_dir = 'doc'
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
task :gemspec => GEMSPEC
|
85
|
-
file GEMSPEC => __FILE__
|
86
|
-
task GEMSPEC do |task|
|
87
|
-
spec = $hoespec.spec
|
88
|
-
spec.files.delete( '.gemtest' )
|
89
|
-
spec.signing_key = nil
|
90
|
-
spec.cert_chain = [ 'certs/mahlon.pem', 'certs/ged.pem' ]
|
91
|
-
spec.version = "#{spec.version.bump}.0.pre#{Time.now.strftime("%Y%m%d%H%M%S")}"
|
92
|
-
File.open( task.name, 'w' ) do |fh|
|
93
|
-
fh.write( spec.to_ruby )
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
CLOBBER.include( GEMSPEC.to_s )
|
98
|
-
task :default => :gemspec
|
data/lib/strelka.rb
CHANGED
data/lib/strelka/app.rb
CHANGED
@@ -32,7 +32,7 @@ class Strelka::App < Mongrel2::Handler
|
|
32
32
|
|
33
33
|
##
|
34
34
|
# 'Developer mode' flag.
|
35
|
-
setting :devmode, default:
|
35
|
+
setting :devmode, default: false
|
36
36
|
|
37
37
|
end
|
38
38
|
|
@@ -40,7 +40,6 @@ class Strelka::App < Mongrel2::Handler
|
|
40
40
|
# Class instance variables
|
41
41
|
@devmode = false
|
42
42
|
@default_type = nil
|
43
|
-
@loading_file = nil
|
44
43
|
@subclasses = Hash.new {|h,k| h[k] = [] }
|
45
44
|
|
46
45
|
|
@@ -54,7 +53,7 @@ class Strelka::App < Mongrel2::Handler
|
|
54
53
|
### Developer mode is mostly informational by default (it just makes logging more
|
55
54
|
### verbose), but plugins and such might alter their behavior based on this setting.
|
56
55
|
def self::devmode?
|
57
|
-
return @devmode
|
56
|
+
return @devmode
|
58
57
|
end
|
59
58
|
singleton_method_alias :in_devmode?, :devmode?
|
60
59
|
|
@@ -8,11 +8,10 @@ require 'strelka/plugins'
|
|
8
8
|
require 'strelka/paramvalidator'
|
9
9
|
|
10
10
|
|
11
|
-
# Parameter validation
|
11
|
+
# Parameter validation for Strelka apps.
|
12
12
|
#
|
13
|
-
# When you include the +:parameters+ plugin, you can declare valid parameters
|
14
|
-
# constraints that describe what
|
15
|
-
# values that match.
|
13
|
+
# When you include the +:parameters+ plugin, you can declare valid parameters and specify
|
14
|
+
# constraints that describe what incoming values should match.
|
16
15
|
#
|
17
16
|
# == Parameter Declaration
|
18
17
|
#
|
@@ -101,14 +100,6 @@ module Strelka::App::Parameters
|
|
101
100
|
end
|
102
101
|
|
103
102
|
|
104
|
-
### Get/set the untainting flag. If set, all parameters which match their constraints
|
105
|
-
### will also be untainted.
|
106
|
-
def untaint_all_constraints( newval=nil )
|
107
|
-
self.paramvalidator.untaint_all = newval unless newval.nil?
|
108
|
-
return self.paramvalidator.untaint_all?
|
109
|
-
end
|
110
|
-
|
111
|
-
|
112
103
|
### Inheritance hook -- inheriting classes inherit their parents' parameter
|
113
104
|
### declarations, too.
|
114
105
|
def inherited( subclass )
|
@@ -152,9 +152,6 @@ module Strelka::App::RestResources
|
|
152
152
|
route = [ options[:prefix], name ].compact.join( '/' )
|
153
153
|
self.log.warn "Route is: %p" % [[ options[:prefix], name ]]
|
154
154
|
|
155
|
-
# Ensure validated parameters are untainted
|
156
|
-
self.untaint_all_constraints
|
157
|
-
|
158
155
|
# Make and install handler methods
|
159
156
|
self.log.debug " adding readers"
|
160
157
|
self.add_options_handler( route, rsrcobj, options )
|
data/lib/strelka/cookie.rb
CHANGED
@@ -79,7 +79,7 @@ class Strelka::Cookie
|
|
79
79
|
raise Strelka::ParseError, "malformed cookie pair: %p" % [ cookie_pair ]
|
80
80
|
|
81
81
|
# self.log.debug " matched cookie: %p" % [ match ]
|
82
|
-
name = match[:cookie_name]
|
82
|
+
name = match[:cookie_name]
|
83
83
|
value = match[:cookie_value]
|
84
84
|
value = self.dequote( value ) if value.start_with?( DQUOTE )
|
85
85
|
value = nil if value.empty?
|
data/lib/strelka/mixins.rb
CHANGED
data/lib/strelka/multirunner.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
require 'strelka' unless defined?( Strelka )
|
6
6
|
require 'strelka/signal_handling'
|
7
7
|
|
8
|
-
# Load multiple
|
8
|
+
# Load multiple simultaneous Strelka handlers (of a single type) with
|
9
9
|
# proper signal handling.
|
10
10
|
#
|
11
11
|
class Strelka::MultiRunner
|
@@ -53,7 +53,9 @@ class Strelka::MultiRunner
|
|
53
53
|
|
54
54
|
self.log.debug "Starting multirunner loop..."
|
55
55
|
self.spawn_children
|
56
|
-
|
56
|
+
while self.running
|
57
|
+
self.reap_children if self.wait_for_signals
|
58
|
+
end
|
57
59
|
self.log.debug "Ending multirunner."
|
58
60
|
|
59
61
|
# Restore the default signal handlers
|
@@ -81,16 +83,37 @@ class Strelka::MultiRunner
|
|
81
83
|
end
|
82
84
|
|
83
85
|
|
84
|
-
###
|
85
|
-
|
86
|
-
|
87
|
-
self.
|
88
|
-
|
89
|
-
Process.kill( signal, pid )
|
90
|
-
pid, status = Process.waitpid2( pid, Process::WUNTRACED )
|
91
|
-
self.log.debug " waitpid2 returned: [ %p, %p ]" % [ pid, status ]
|
86
|
+
### Clean up after any children that have died.
|
87
|
+
def reap_children
|
88
|
+
pid, status = Process.waitpid2( -1, Process::WNOHANG|Process::WUNTRACED )
|
89
|
+
self.log.debug " waitpid2 returned: [ %p, %p ]" % [ pid, status ]
|
90
|
+
while pid
|
92
91
|
self.handler_pids.delete( pid )
|
92
|
+
pid, status = Process.waitpid2( -1, Process::WNOHANG|Process::WUNTRACED )
|
93
|
+
self.log.debug " waitpid2 returned: [ %p, %p ]" % [ pid, status ]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
### Kill all current children with the specified +signal+. Returns
|
99
|
+
### +true+ if the signal was sent to one or more children.
|
100
|
+
def kill_children( signal=:TERM )
|
101
|
+
return false if self.handler_pids.empty?
|
102
|
+
|
103
|
+
self.log.info "Sending %s signal to %d task pids: %p." %
|
104
|
+
[ signal, self.handler_pids.length, self.handler_pids ]
|
105
|
+
self.handler_pids.each do |pid|
|
106
|
+
begin
|
107
|
+
Process.kill( signal, pid )
|
108
|
+
rescue Errno::ESRCH => err
|
109
|
+
self.log.error "%p when trying to %s child %d: %s" %
|
110
|
+
[ err.class, signal, pid, err.message ]
|
111
|
+
end
|
93
112
|
end
|
113
|
+
|
114
|
+
return true
|
115
|
+
rescue Errno::ESRCH
|
116
|
+
self.log.debug "Ignoring signals to unreaped children."
|
94
117
|
end
|
95
118
|
|
96
119
|
|
@@ -101,7 +124,7 @@ class Strelka::MultiRunner
|
|
101
124
|
when :INT, :TERM, :QUIT
|
102
125
|
if @running
|
103
126
|
self.log.warn "%s signal: graceful shutdown" % [ sig ]
|
104
|
-
self.
|
127
|
+
self.kill_children( sig )
|
105
128
|
@running = false
|
106
129
|
else
|
107
130
|
self.ignore_signals
|
@@ -26,10 +26,7 @@ require 'strelka/app' unless defined?( Strelka::App )
|
|
26
26
|
# validator.add( :feedback, :printable, "Customer Feedback" )
|
27
27
|
# validator.override( :email, :printable, "Your Email Address" )
|
28
28
|
#
|
29
|
-
# #
|
30
|
-
# validate.untaint_all_constraints = true
|
31
|
-
#
|
32
|
-
# # Now pass in tainted values in a hash (e.g., from an HTML form)
|
29
|
+
# # Now pass in values in a hash (e.g., from an HTML form)
|
33
30
|
# validator.validate( req.params )
|
34
31
|
#
|
35
32
|
# # Now if there weren't any errors, use some form values to fill out the
|
@@ -79,7 +76,7 @@ class Strelka::ParamValidator
|
|
79
76
|
|
80
77
|
|
81
78
|
# Flags that are passed as Symbols when declaring a parameter
|
82
|
-
FLAGS = [ :required, :
|
79
|
+
FLAGS = [ :required, :multiple ]
|
83
80
|
|
84
81
|
# Map of constraint specification types to their equivalent Constraint class.
|
85
82
|
TYPES = { Proc => self }
|
@@ -124,7 +121,6 @@ class Strelka::ParamValidator
|
|
124
121
|
@description = args.shift if args.first.is_a?( String )
|
125
122
|
|
126
123
|
@required = args.include?( :required )
|
127
|
-
@untaint = args.include?( :untaint )
|
128
124
|
@multiple = args.include?( :multiple )
|
129
125
|
end
|
130
126
|
|
@@ -151,19 +147,13 @@ class Strelka::ParamValidator
|
|
151
147
|
# order for the parameters to be valid.
|
152
148
|
attr_predicate :required?
|
153
149
|
|
154
|
-
##
|
155
|
-
# Returns true if the constraint will also untaint its result before returning it.
|
156
|
-
attr_predicate :untaint?
|
157
|
-
|
158
150
|
|
159
151
|
### Check the given value against the constraint and return the result if it passes.
|
160
|
-
def apply( value
|
161
|
-
untaint = self.untaint? || force_untaint
|
162
|
-
|
152
|
+
def apply( value )
|
163
153
|
if self.multiple?
|
164
|
-
return self.check_multiple( value
|
154
|
+
return self.check_multiple( value )
|
165
155
|
else
|
166
|
-
return self.check( value
|
156
|
+
return self.check( value )
|
167
157
|
end
|
168
158
|
end
|
169
159
|
|
@@ -190,7 +180,6 @@ class Strelka::ParamValidator
|
|
190
180
|
flags = []
|
191
181
|
flags << 'required' if self.required?
|
192
182
|
flags << 'multiple' if self.multiple?
|
193
|
-
flags << 'untaint' if self.untaint?
|
194
183
|
|
195
184
|
desc << " (%s)" % [ flags.join(',') ] unless flags.empty?
|
196
185
|
|
@@ -218,21 +207,20 @@ class Strelka::ParamValidator
|
|
218
207
|
### Check the specified value against the constraint and return the results. By
|
219
208
|
### default, this just calls to_proc and the block and calls the result with the
|
220
209
|
### value as its argument.
|
221
|
-
def check( value
|
210
|
+
def check( value )
|
222
211
|
return self.block.to_proc.call( value ) if self.block
|
223
|
-
value.untaint if untaint && value.respond_to?( :untaint )
|
224
212
|
return value
|
225
213
|
end
|
226
214
|
|
227
215
|
|
228
216
|
### Check the given +values+ against the constraint and return the results if
|
229
217
|
### all of them succeed.
|
230
|
-
def check_multiple( values
|
218
|
+
def check_multiple( values )
|
231
219
|
values = [ values ] unless values.is_a?( Array )
|
232
220
|
results = []
|
233
221
|
|
234
222
|
values.each do |value|
|
235
|
-
result = self.check( value
|
223
|
+
result = self.check( value ) or return nil
|
236
224
|
results << result
|
237
225
|
end
|
238
226
|
|
@@ -280,38 +268,35 @@ class Strelka::ParamValidator
|
|
280
268
|
|
281
269
|
### Check the +value+ against the regular expression and return its
|
282
270
|
### match groups if successful.
|
283
|
-
def check( value
|
271
|
+
def check( value )
|
284
272
|
self.log.debug "Validating %p via regexp %p" % [ value, self.pattern ]
|
285
273
|
match = self.pattern.match( value.to_s ) or return nil
|
286
274
|
|
287
275
|
if match.captures.empty?
|
288
276
|
self.log.debug " no captures, using whole match: %p" % [match[0]]
|
289
|
-
return super( match[0]
|
277
|
+
return super( match[0] )
|
290
278
|
|
291
279
|
elsif match.names.length > 1
|
292
280
|
self.log.debug " extracting hash of named captures: %p" % [ match.names ]
|
293
|
-
rhash = self.matched_hash( match
|
294
|
-
return super( rhash
|
281
|
+
rhash = self.matched_hash( match )
|
282
|
+
return super( rhash )
|
295
283
|
|
296
284
|
elsif match.captures.length == 1
|
297
285
|
self.log.debug " extracting one capture: %p" % [match.captures.first]
|
298
|
-
return super( match.captures.first
|
286
|
+
return super( match.captures.first )
|
299
287
|
|
300
288
|
else
|
301
289
|
self.log.debug " extracting multiple captures: %p" % [match.captures]
|
302
290
|
values = match.captures
|
303
|
-
|
304
|
-
return super( values, untaint )
|
291
|
+
return super( values )
|
305
292
|
end
|
306
293
|
end
|
307
294
|
|
308
295
|
|
309
|
-
### Return a Hash of the given +match+ object's named captures
|
310
|
-
|
311
|
-
def matched_hash( match, untaint )
|
296
|
+
### Return a Hash of the given +match+ object's named captures.
|
297
|
+
def matched_hash( match )
|
312
298
|
return match.names.inject( {} ) do |accum,name|
|
313
299
|
value = match[ name ]
|
314
|
-
value.untaint if untaint && value
|
315
300
|
accum[ name.to_sym ] = value
|
316
301
|
accum
|
317
302
|
end
|
@@ -566,7 +551,6 @@ class Strelka::ParamValidator
|
|
566
551
|
def initialize
|
567
552
|
@constraints = {}
|
568
553
|
@fields = {}
|
569
|
-
@untaint_all = false
|
570
554
|
|
571
555
|
self.reset
|
572
556
|
end
|
@@ -591,12 +575,6 @@ class Strelka::ParamValidator
|
|
591
575
|
# The Hash of raw field data (if validation has occurred)
|
592
576
|
attr_reader :fields
|
593
577
|
|
594
|
-
##
|
595
|
-
# Global untainting flag
|
596
|
-
attr_predicate_accessor :untaint_all?
|
597
|
-
alias_method :untaint_all_constraints=, :untaint_all=
|
598
|
-
alias_method :untaint_all_constraints?, :untaint_all?
|
599
|
-
|
600
578
|
##
|
601
579
|
# Returns +true+ if the paramvalidator has been given parameters to validate. Adding or
|
602
580
|
# overriding constraints resets this.
|
@@ -680,13 +658,12 @@ class Strelka::ParamValidator
|
|
680
658
|
constraint.required?
|
681
659
|
end
|
682
660
|
|
683
|
-
return "#<%p:0x%016x %s, profile: [required: %s, optional: %s]
|
661
|
+
return "#<%p:0x%016x %s, profile: [required: %s, optional: %s]>" % [
|
684
662
|
self.class,
|
685
663
|
self.object_id / 2,
|
686
664
|
self.to_s,
|
687
665
|
required.empty? ? "(none)" : required.map( &:last ).map( &:name ).join(','),
|
688
666
|
optional.empty? ? "(none)" : optional.map( &:last ).map( &:name ).join(','),
|
689
|
-
self.untaint_all? ? "enabled" : "disabled",
|
690
667
|
]
|
691
668
|
end
|
692
669
|
|
@@ -754,7 +731,7 @@ class Strelka::ParamValidator
|
|
754
731
|
### result.
|
755
732
|
def apply_constraint( constraint, value )
|
756
733
|
if !( value.nil? || value == '' )
|
757
|
-
result = constraint.apply( value
|
734
|
+
result = constraint.apply( value )
|
758
735
|
|
759
736
|
if !result.nil?
|
760
737
|
self.log.debug " constraint for %p passed: %p" % [ constraint.name, result ]
|
@@ -976,7 +953,7 @@ class Strelka::ParamValidator
|
|
976
953
|
### Build a deep hash out of the given parameter +value+
|
977
954
|
def build_deep_hash( value, hash, levels )
|
978
955
|
if levels.length == 0
|
979
|
-
value
|
956
|
+
value
|
980
957
|
elsif hash.nil?
|
981
958
|
{ levels.first => build_deep_hash(value, nil, levels[1..-1]) }
|
982
959
|
else
|
@@ -992,11 +969,11 @@ class Strelka::ParamValidator
|
|
992
969
|
if main.nil?
|
993
970
|
return []
|
994
971
|
elsif trailing
|
995
|
-
return [key
|
972
|
+
return [key]
|
996
973
|
elsif bracketed
|
997
|
-
return [main
|
974
|
+
return [main] + bracketed.slice(1...-1).split('][')
|
998
975
|
else
|
999
|
-
return [main
|
976
|
+
return [main]
|
1000
977
|
end
|
1001
978
|
end
|
1002
979
|
|