Skip to content

Commit

Permalink
Removed content-type check from Mechanize::Page to allow parsing of i…
Browse files Browse the repository at this point in the history
…ncorrect or missing content-types. Fixes sparklemotion#221
  • Loading branch information
drbrain committed May 8, 2012
1 parent 2a6edf9 commit 36d06f5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 39 deletions.
2 changes: 0 additions & 2 deletions lib/mechanize/page.rb
Expand Up @@ -26,8 +26,6 @@ class Mechanize::Page < Mechanize::File

def initialize(uri=nil, response=nil, body=nil, code=nil, mech=nil)
response ||= DEFAULT_RESPONSE
raise Mechanize::ContentTypeError, response['content-type'] unless
response['content-type'] =~ %r{\A(?:text/html|application/xhtml\+xml)(?:$|\s*[\s;,])}i

@meta_content_type = nil
@encoding = nil
Expand Down
8 changes: 3 additions & 5 deletions test/test_mechanize_page.rb
Expand Up @@ -38,12 +38,10 @@ def test_initialize_bad_content_type
'application/xhtml+xmlfu',
'fooapplication/xhtml+xml',
].each { |content_type|
e = assert_raises(Mechanize::ContentTypeError, content_type) do
Mechanize::Page.new(URI('http://example/'),
{ 'content-type' => content_type }, 'hello', '200')
end
page = Mechanize::Page.new(URI('http://example/'),
{ 'content-type' => content_type }, 'hello', '200')

assert_equal(content_type, e.content_type, content_type)
assert_equal(content_type, page.content_type, content_type)
}
end

Expand Down
32 changes: 0 additions & 32 deletions test/test_mechanize_page_link.rb
Expand Up @@ -52,38 +52,6 @@ def util_page body = @body, res = @res
Mechanize::Page.new @uri, res, body, 200, @mech
end

def test_initialize_supported_content_type
page = Mechanize::Page.new nil, 'content-type' => 'application/xhtml+xml'
assert page
assert_equal 'application/xhtml+xml', page.content_type

page = Mechanize::Page.new nil, 'content-type' => 'text/html'
assert page
assert_equal 'text/html', page.content_type

page = Mechanize::Page.new nil, 'content-type' => 'application/xhtml+xml;charset=utf-8'
assert page
assert_equal 'application/xhtml+xml;charset=utf-8', page.content_type

page = Mechanize::Page.new nil, 'content-type' => 'text/html;charset=utf-8'
assert page
assert_equal 'text/html;charset=utf-8', page.content_type
end

def test_initialize_unsupported_content_type
e = assert_raises Mechanize::ContentTypeError do
Mechanize::Page.new nil, 'content-type' => 'text/plain'
end

assert_equal 'text/plain', e.content_type

e = assert_raises Mechanize::ContentTypeError do
Mechanize::Page.new nil, 'content-type' => 'text/plain;charset=utf-8'
end

assert_equal 'text/plain;charset=utf-8', e.content_type
end

def test_override_content_type
page = Mechanize::Page.new nil, {'content-type' => 'text/html'}, WINDOWS_1255
assert page
Expand Down

0 comments on commit 36d06f5

Please sign in to comment.