diff --git a/app/metal/itex.rb b/app/metal/itex.rb index b63c027a..63e300bb 100644 --- a/app/metal/itex.rb +++ b/app/metal/itex.rb @@ -13,30 +13,63 @@ class Itex end private - + + # plugable XML parser; falls back to REXML + begin + require 'nokogiri' + def self.xmlparse(text) + Nokogiri::XML(text) { |config| config.options = Nokogiri::XML::ParseOptions::STRICT } + end + rescue LoadError + require 'rexml/document' + def self.xmlparse(text) + REXML::Document.new(text) + end + end + + #error message to return + def self.error(str) + "" + + str + "" + end + + # itex2MML parser + begin + require 'itextomml' + def self.parse_itex(tex, filter) + Itex2MML::Parser.new.send(filter, tex).to_utf8 + end + rescue LoadError + def self.parse_itex(tex, filter) + error("Please install the itex2MML Ruby bindings.") + end + end + + # the actual response def self.response(env) - @params = Rack::Request.new(env).params - tex = (@params['tex'] || '').purify - case @params['display'] + params = Rack::Request.new(env).params + tex = (params['tex'] || '').purify.strip + case params['display'] when 'block' filter = :block_filter else filter = :inline_filter end return "" if tex.strip == '' - estart = "" - eend = "" + filter.to_s[/(.*?)_filter/] + "'/>" if tex == '' begin - require 'itextomml' - @itex2mml_parser ||= Itex2MML::Parser.new - @itex2mml_parser.send(filter, tex).to_utf8 - rescue LoadError - estart + "Please install the itex2MML Ruby bindings." + eend + doc = parse_itex(tex, filter) + # make sure the result is well-formed, before sending it off + begin + xmlparse(doc) + rescue + return error("Ill-formed XML.") + end + return doc rescue Itex2MML::Error => e - estart + e.to_s + eend + error(e.to_s) rescue - estart + "Unknown Error" + eend + error("Unknown Error") end end end diff --git a/app/views/layouts/error.html.erb b/app/views/layouts/error.html.erb index cbdd1596..5c03dfce 100644 --- a/app/views/layouts/error.html.erb +++ b/app/views/layouts/error.html.erb @@ -31,7 +31,11 @@
-<%= h @content_for_layout %> +<%= if :raw + @content_for_layout + else + h @content_for_layout + end %>
diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index ebd1166d..c63d4019 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -765,6 +765,11 @@ class WikiControllerTest < ActionController::TestCase 'author' => 'AuthorOfNewPage' assert_equal 403, r.response_code + resp = %{

Access denied. Your IP address, 127.0.0.2, was found on one or more DNSBL blocking } + + %{list(s).

\n

See here for more information.

\n

See here for more information.

\n} + assert_match Regexp.new(Regexp.escape(resp)), r.body end def test_dnsbl_filter_allow_action diff --git a/vendor/plugins/dnsbl_check/lib/dnsbl_check.rb b/vendor/plugins/dnsbl_check/lib/dnsbl_check.rb index a3bd44d1..c1ab3b06 100644 --- a/vendor/plugins/dnsbl_check/lib/dnsbl_check.rb +++ b/vendor/plugins/dnsbl_check/lib/dnsbl_check.rb @@ -45,7 +45,7 @@ module DNSBL_Check addr = Resolv.getaddress("#{host}") rescue '' if addr[0,7]=="127.0.0" logger.info("#{request.remote_addr} found using DNSBL #{host}") - ban_help << " See here for more information." + ban_help << "\n

See here for more information.

" passed = false end end @@ -58,8 +58,8 @@ module DNSBL_Check $dnsbl_passed.push request.remote_addr logger.warn("#{request.remote_addr} added to DNSBL passed cache") else - render( :text => "Access denied. Your IP address, #{request.remote_addr}, was found on one or more DNSBL" + - " blocking list(s).#{ban_help}", :status => 403, :layout => 'error') + render( :text => "

Access denied. Your IP address, #{request.remote_addr}, was found on one or more DNSBL" + + " blocking list(s).

#{ban_help}", :status => 403, :layout => 'error', :locals => {:raw => true}) return false end end