padrino-core 0.11.1 → 0.11.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.
- data/lib/padrino-core/application/routing.rb +19 -2
- data/lib/padrino-core/application.rb +4 -2
- data/lib/padrino-core/server.rb +1 -1
- data/lib/padrino-core/version.rb +1 -1
- data/padrino-core.gemspec +1 -1
- data/test/mini_shoulda.rb +1 -1
- data/test/test_routing.rb +37 -0
- metadata +5 -5
@@ -100,6 +100,20 @@ class HttpRouter
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
+
#Monkey patching the Request class. Using Rack::Utils.unescape rather than
|
104
|
+
#URI.unescape which can't handle utf-8 chars
|
105
|
+
class Request
|
106
|
+
def initialize(path, rack_request)
|
107
|
+
@rack_request = rack_request
|
108
|
+
@path = Rack::Utils.unescape(path).split(/\//)
|
109
|
+
@path.shift if @path.first == ''
|
110
|
+
@path.push('') if path[-1] == ?/
|
111
|
+
@extra_env = {}
|
112
|
+
@params = []
|
113
|
+
@acceptable_methods = Set.new
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
103
117
|
class Node::Path
|
104
118
|
def to_code
|
105
119
|
path_ivar = inject_root_ivar(self)
|
@@ -813,7 +827,7 @@ module Padrino
|
|
813
827
|
def provides(*types)
|
814
828
|
@_use_format = true
|
815
829
|
condition do
|
816
|
-
mime_types = types.map { |t| mime_type(t) }
|
830
|
+
mime_types = types.map { |t| mime_type(t) }.compact
|
817
831
|
url_format = params[:format].to_sym if params[:format]
|
818
832
|
accepts = request.accept.map { |a| a.to_str }
|
819
833
|
|
@@ -821,11 +835,14 @@ module Padrino
|
|
821
835
|
# Assume */* if no ACCEPT header is given.
|
822
836
|
catch_all = (accepts.delete "*/*" || accepts.empty?)
|
823
837
|
matching_types = accepts.empty? ? mime_types.slice(0,1) : (accepts & mime_types)
|
838
|
+
if matching_types.empty? && types.include?(:any)
|
839
|
+
matching_types = accepts
|
840
|
+
end
|
824
841
|
|
825
842
|
if !url_format && matching_types.first
|
826
843
|
type = ::Rack::Mime::MIME_TYPES.find { |k, v| v == matching_types.first }[0].sub(/\./,'').to_sym
|
827
844
|
accept_format = CONTENT_TYPE_ALIASES[type] || type
|
828
|
-
elsif catch_all
|
845
|
+
elsif catch_all && !types.include?(:any)
|
829
846
|
type = types.first
|
830
847
|
accept_format = CONTENT_TYPE_ALIASES[type] || type
|
831
848
|
end
|
@@ -280,9 +280,11 @@ ERROR
|
|
280
280
|
if allow_disabled_csrf?
|
281
281
|
builder.use Rack::Protection::AuthenticityToken,
|
282
282
|
:reaction => :report,
|
283
|
-
:report_key => 'protection.csrf.failed'
|
283
|
+
:report_key => 'protection.csrf.failed',
|
284
|
+
:logger => logger
|
284
285
|
else
|
285
|
-
builder.use Rack::Protection::AuthenticityToken
|
286
|
+
builder.use Rack::Protection::AuthenticityToken,
|
287
|
+
:logger => logger
|
286
288
|
end
|
287
289
|
end
|
288
290
|
end
|
data/lib/padrino-core/server.rb
CHANGED
@@ -27,7 +27,7 @@ module Padrino
|
|
27
27
|
options[:Port] = options.delete(:port) || 3000
|
28
28
|
options[:AccessLog] = []
|
29
29
|
if options[:daemonize]
|
30
|
-
options[:pid] = options[:pid].blank? ?
|
30
|
+
options[:pid] = File.expand_path(options[:pid].blank? ? 'tmp/pids/server.pid' : opts[:pid])
|
31
31
|
FileUtils.mkdir_p(File.dirname(options[:pid]))
|
32
32
|
end
|
33
33
|
options[:server] = detect_rack_handler if options[:server].blank?
|
data/lib/padrino-core/version.rb
CHANGED
data/padrino-core.gemspec
CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
# s.post_install_message << " as shown here:\e[0m https://gist.github.com/1d36a35794dbbd664ea4"
|
31
31
|
# s.post_install_message << "\n\e[32m" + ("*" * 20) + "\n\e[0m"
|
32
32
|
|
33
|
-
s.add_dependency("tilt", "~> 1.3.
|
33
|
+
s.add_dependency("tilt", "~> 1.3.7")
|
34
34
|
if ENV["SINATRA_EDGE"]
|
35
35
|
s.add_dependency("sinatra")
|
36
36
|
else
|
data/test/mini_shoulda.rb
CHANGED
data/test/test_routing.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
#encoding: utf-8
|
1
2
|
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
2
3
|
|
3
4
|
class FooError < RuntimeError; end
|
@@ -100,6 +101,24 @@ describe "Routing" do
|
|
100
101
|
assert_equal "no access", body
|
101
102
|
end
|
102
103
|
|
104
|
+
should 'parse routes that are encoded' do
|
105
|
+
mock_app do
|
106
|
+
get('/щч') { 'success!' }
|
107
|
+
end
|
108
|
+
get(URI.escape('/щч'))
|
109
|
+
assert_equal 'success!', body
|
110
|
+
end
|
111
|
+
|
112
|
+
should 'encode params using UTF-8' do
|
113
|
+
skip unless ''.respond_to?(:encoding) # for 1.8.7
|
114
|
+
|
115
|
+
mock_app do
|
116
|
+
get('/:foo') { params[:foo].encoding.name }
|
117
|
+
end
|
118
|
+
get '/bar'
|
119
|
+
assert_equal 'UTF-8', body
|
120
|
+
end
|
121
|
+
|
103
122
|
should 'match correctly similar paths' do
|
104
123
|
mock_app do
|
105
124
|
get("/my/:foo_id"){ params[:foo_id] }
|
@@ -1122,6 +1141,24 @@ describe "Routing" do
|
|
1122
1141
|
assert_equal 'js', body
|
1123
1142
|
end
|
1124
1143
|
|
1144
|
+
should "set content_type to :html if Accept */* and provides of :any" do
|
1145
|
+
mock_app do
|
1146
|
+
get("/foo", :provides => :any) { content_type.to_s }
|
1147
|
+
end
|
1148
|
+
|
1149
|
+
get '/foo', {}, { 'HTTP_ACCEPT' => '*/*' }
|
1150
|
+
assert_equal 'html', body
|
1151
|
+
end
|
1152
|
+
|
1153
|
+
should "set content_type to :js if Accept includes both application/javascript, */*;q=0.5 and provides of :any" do
|
1154
|
+
mock_app do
|
1155
|
+
get("/foo", :provides => :any) { content_type.to_s }
|
1156
|
+
end
|
1157
|
+
|
1158
|
+
get '/foo', {}, { 'HTTP_ACCEPT' => 'application/javascript, */*;q=0.5' }
|
1159
|
+
assert_equal 'js', body
|
1160
|
+
end
|
1161
|
+
|
1125
1162
|
should 'allows custom route-conditions to be set via route options and halt' do
|
1126
1163
|
protector = Module.new do
|
1127
1164
|
def protect(*args)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2013-
|
15
|
+
date: 2013-05-21 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: tilt
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
requirements:
|
22
22
|
- - ~>
|
23
23
|
- !ruby/object:Gem::Version
|
24
|
-
version: 1.3.
|
24
|
+
version: 1.3.7
|
25
25
|
type: :runtime
|
26
26
|
prerelease: false
|
27
27
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 1.3.
|
32
|
+
version: 1.3.7
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: sinatra
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -224,7 +224,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
224
224
|
version: '0'
|
225
225
|
segments:
|
226
226
|
- 0
|
227
|
-
hash:
|
227
|
+
hash: 3143622035712023707
|
228
228
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
229
229
|
none: false
|
230
230
|
requirements:
|