parent
63e81bc539
commit
b4fdb7221f
|
@ -603,11 +603,6 @@ module Sinatra
|
||||||
status.between? 500, 599
|
status.between? 500, 599
|
||||||
end
|
end
|
||||||
|
|
||||||
# whether or not the status is set to 400
|
|
||||||
def bad_request?
|
|
||||||
status == 400
|
|
||||||
end
|
|
||||||
|
|
||||||
# whether or not the status is set to 404
|
# whether or not the status is set to 404
|
||||||
def not_found?
|
def not_found?
|
||||||
status == 404
|
status == 404
|
||||||
|
@ -1143,9 +1138,6 @@ module Sinatra
|
||||||
elsif not_found?
|
elsif not_found?
|
||||||
headers['X-Cascade'] = 'pass' if settings.x_cascade?
|
headers['X-Cascade'] = 'pass' if settings.x_cascade?
|
||||||
body '<h1>Not Found</h1>'
|
body '<h1>Not Found</h1>'
|
||||||
elsif bad_request?
|
|
||||||
dump_errors! boom if settings.dump_errors?
|
|
||||||
halt status
|
|
||||||
end
|
end
|
||||||
|
|
||||||
res = error_block!(boom.class, boom) || error_block!(status, boom)
|
res = error_block!(boom.class, boom) || error_block!(status, boom)
|
||||||
|
|
|
@ -49,6 +49,10 @@ module Sinatra
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def bad_request?(e)
|
||||||
|
Sinatra::BadRequest === e
|
||||||
|
end
|
||||||
|
|
||||||
def prefers_plain_text?(env)
|
def prefers_plain_text?(env)
|
||||||
!(Request.new(env).preferred_type("text/plain","text/html") == "text/html") &&
|
!(Request.new(env).preferred_type("text/plain","text/html") == "text/html") &&
|
||||||
[/curl/].index { |item| item =~ env["HTTP_USER_AGENT"] }
|
[/curl/].index { |item| item =~ env["HTTP_USER_AGENT"] }
|
||||||
|
@ -210,8 +214,10 @@ TEMPLATE = ERB.new <<-HTML # :nodoc:
|
||||||
<p><a href="#" id="expando"
|
<p><a href="#" id="expando"
|
||||||
onclick="toggleBacktrace(); return false">(expand)</a></p>
|
onclick="toggleBacktrace(); return false">(expand)</a></p>
|
||||||
<p id="nav"><strong>JUMP TO:</strong>
|
<p id="nav"><strong>JUMP TO:</strong>
|
||||||
<a href="#get-info">GET</a>
|
<% unless bad_request?(exception) %>
|
||||||
<a href="#post-info">POST</a>
|
<a href="#get-info">GET</a>
|
||||||
|
<a href="#post-info">POST</a>
|
||||||
|
<% end %>
|
||||||
<a href="#cookie-info">COOKIES</a>
|
<a href="#cookie-info">COOKIES</a>
|
||||||
<a href="#env-info">ENV</a>
|
<a href="#env-info">ENV</a>
|
||||||
</p>
|
</p>
|
||||||
|
@ -264,47 +270,49 @@ TEMPLATE = ERB.new <<-HTML # :nodoc:
|
||||||
</ul>
|
</ul>
|
||||||
</div> <!-- /BACKTRACE -->
|
</div> <!-- /BACKTRACE -->
|
||||||
|
|
||||||
<div id="get">
|
<% unless bad_request?(exception) %>
|
||||||
<h3 id="get-info">GET</h3>
|
<div id="get">
|
||||||
<% if req.GET and not req.GET.empty? %>
|
<h3 id="get-info">GET</h3>
|
||||||
<table class="req">
|
<% if req.GET and not req.GET.empty? %>
|
||||||
<tr>
|
<table class="req">
|
||||||
<th>Variable</th>
|
<tr>
|
||||||
<th>Value</th>
|
<th>Variable</th>
|
||||||
</tr>
|
<th>Value</th>
|
||||||
<% req.GET.sort_by { |k, v| k.to_s }.each { |key, val| %>
|
</tr>
|
||||||
<tr>
|
<% req.GET.sort_by { |k, v| k.to_s }.each { |key, val| %>
|
||||||
<td><%=h key %></td>
|
<tr>
|
||||||
<td class="code"><div><%=h val.inspect %></div></td>
|
<td><%=h key %></td>
|
||||||
</tr>
|
<td class="code"><div><%=h val.inspect %></div></td>
|
||||||
<% } %>
|
</tr>
|
||||||
</table>
|
<% } %>
|
||||||
<% else %>
|
</table>
|
||||||
<p class="no-data">No GET data.</p>
|
<% else %>
|
||||||
<% end %>
|
<p class="no-data">No GET data.</p>
|
||||||
<div class="clear"></div>
|
<% end %>
|
||||||
</div> <!-- /GET -->
|
<div class="clear"></div>
|
||||||
|
</div> <!-- /GET -->
|
||||||
|
|
||||||
<div id="post">
|
<div id="post">
|
||||||
<h3 id="post-info">POST</h3>
|
<h3 id="post-info">POST</h3>
|
||||||
<% if req.POST and not req.POST.empty? %>
|
<% if req.POST and not req.POST.empty? %>
|
||||||
<table class="req">
|
<table class="req">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Variable</th>
|
<th>Variable</th>
|
||||||
<th>Value</th>
|
<th>Value</th>
|
||||||
</tr>
|
</tr>
|
||||||
<% req.POST.sort_by { |k, v| k.to_s }.each { |key, val| %>
|
<% req.POST.sort_by { |k, v| k.to_s }.each { |key, val| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%=h key %></td>
|
<td><%=h key %></td>
|
||||||
<td class="code"><div><%=h val.inspect %></div></td>
|
<td class="code"><div><%=h val.inspect %></div></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% } %>
|
<% } %>
|
||||||
</table>
|
</table>
|
||||||
<% else %>
|
<% else %>
|
||||||
<p class="no-data">No POST data.</p>
|
<p class="no-data">No POST data.</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
</div> <!-- /POST -->
|
</div> <!-- /POST -->
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<div id="cookies">
|
<div id="cookies">
|
||||||
<h3 id="cookie-info">COOKIES</h3>
|
<h3 id="cookie-info">COOKIES</h3>
|
||||||
|
|
|
@ -26,23 +26,6 @@ class HelpersTest < Minitest::Test
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'bad_request?' do
|
|
||||||
it 'is true for status == 400' do
|
|
||||||
status_app(400) { bad_request? }
|
|
||||||
assert_body 'true'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'is false for status gt 400' do
|
|
||||||
status_app(401) { bad_request? }
|
|
||||||
assert_body 'false'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'is false for status lt 400' do
|
|
||||||
status_app(399) { bad_request? }
|
|
||||||
assert_body 'false'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'not_found?' do
|
describe 'not_found?' do
|
||||||
it 'is true for status == 404' do
|
it 'is true for status == 404' do
|
||||||
status_app(404) { not_found? }
|
status_app(404) { not_found? }
|
||||||
|
|
|
@ -54,7 +54,7 @@ class RoutingTest < Minitest::Test
|
||||||
|
|
||||||
request = Rack::MockRequest.new(@app)
|
request = Rack::MockRequest.new(@app)
|
||||||
response = request.request('GET', '/foo?bar=&bar[]=', {})
|
response = request.request('GET', '/foo?bar=&bar[]=', {})
|
||||||
assert response.bad_request?
|
assert_equal 400, response.status
|
||||||
end
|
end
|
||||||
|
|
||||||
it "404s when no route satisfies the request" do
|
it "404s when no route satisfies the request" do
|
||||||
|
|
|
@ -247,6 +247,22 @@ class SettingsTest < Minitest::Test
|
||||||
assert body.include?("<code>show_exceptions</code> setting")
|
assert body.include?("<code>show_exceptions</code> setting")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not attempt to show unparseable query parameters' do
|
||||||
|
klass = Sinatra.new(Sinatra::Application)
|
||||||
|
mock_app(klass) {
|
||||||
|
enable :show_exceptions
|
||||||
|
|
||||||
|
get '/' do
|
||||||
|
raise Sinatra::BadRequest
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
|
get '/'
|
||||||
|
assert_equal 400, status
|
||||||
|
refute body.include?('<div id="get">')
|
||||||
|
refute body.include?('<div id="post">')
|
||||||
|
end
|
||||||
|
|
||||||
it 'does not override app-specified error handling when set to :after_handler' do
|
it 'does not override app-specified error handling when set to :after_handler' do
|
||||||
ran = false
|
ran = false
|
||||||
mock_app do
|
mock_app do
|
||||||
|
|
Loading…
Reference in New Issue