Skip to content

Commit

Permalink
html escape detail for error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Neal Harris committed Jun 23, 2013
1 parent 89cf625 commit 479fe8f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rack/showstatus.rb
Expand Up @@ -96,7 +96,7 @@ def h(obj) # :nodoc:
</table> </table>
</div> </div>
<div id="info"> <div id="info">
<p><%= detail %></p> <p><%=h detail %></p>
</div> </div>
<div id="explanation"> <div id="explanation">
Expand Down
19 changes: 19 additions & 0 deletions test/spec_showstatus.rb
@@ -1,6 +1,7 @@
require 'rack/showstatus' require 'rack/showstatus'
require 'rack/lint' require 'rack/lint'
require 'rack/mock' require 'rack/mock'
require 'rack/utils'


describe Rack::ShowStatus do describe Rack::ShowStatus do
def show_status(app) def show_status(app)
Expand Down Expand Up @@ -40,6 +41,24 @@ def show_status(app)
res.should =~ /too meta/ res.should =~ /too meta/
end end


should "escape error" do
detail = "<script>alert('hi \"')</script>"
req = Rack::MockRequest.new(
show_status(
lambda{|env|
env["rack.showstatus.detail"] = detail
[500, {"Content-Type" => "text/plain", "Content-Length" => "0"}, []]
}))

res = req.get("/", :lint => true)
res.should.be.not.empty

res["Content-Type"].should.equal("text/html")
res.should =~ /500/
res.should.not.include detail
res.body.should.include Rack::Utils.escape_html(detail)
end

should "not replace existing messages" do should "not replace existing messages" do
req = Rack::MockRequest.new( req = Rack::MockRequest.new(
show_status( show_status(
Expand Down

0 comments on commit 479fe8f

Please sign in to comment.