diff --git a/lib/bitclust/screen.rb b/lib/bitclust/screen.rb index bb812b8..360dcc7 100644 --- a/lib/bitclust/screen.rb +++ b/lib/bitclust/screen.rb @@ -654,7 +654,8 @@ def initialize(h, request_full_uri, opt) attr_reader :search_full_url def body - run_template('opensearchdescription') + # XML なので HTML の layout は通さない + run_template('opensearchdescription', false) end def content_type diff --git a/test/test_opensearchdescription_screen.rb b/test/test_opensearchdescription_screen.rb new file mode 100644 index 0000000..14b1f44 --- /dev/null +++ b/test/test_opensearchdescription_screen.rb @@ -0,0 +1,39 @@ +require 'test/unit' +require 'uri' +require 'bitclust' +require 'bitclust/screen' + +class TestOpenSearchDescriptionScreen < Test::Unit::TestCase + SRC = <<'HERE' += class Foo +description +HERE + + def screen + _lib, db = BitClust::RRDParser.parse(SRC, 'testlib', {'version' => '3.4'}) + datadir = File.expand_path('../data/bitclust', __dir__) + manager = BitClust::ScreenManager.new( + :templatedir => "#{datadir}/template", + :catalogdir => "#{datadir}/catalog", + :encoding => 'utf-8', + :default_encoding => 'utf-8', + :base_url => '', + :cgi_url => '/view', + :target_version => '3.4' + ) + manager.opensearchdescription_screen(URI.parse('http://example.com/view/opensearchdescription'), + :database => db) + end + + def test_body_is_bare_xml_without_html_layout + body = screen.body + assert_match(/\A<\?xml/, body) + assert_not_include(body, ']*\?>\s*\s*\z}m, body) + assert_include(body, 'http://example.com/view/search') + end + + def test_content_type_is_opensearch_xml + assert_equal 'application/opensearchdescription+xml; charset=utf-8', screen.content_type + end +end