mirror of https://github.com/scrapy/scrapy.git
fixed bug caused when instantiating selectors with responses containing empty bodies
This commit is contained in:
parent
53ae45ad3d
commit
7baff2914a
|
|
@ -24,7 +24,7 @@ def body_as_utf8(response):
|
|||
|
||||
def xmlDoc_from_html(response):
|
||||
"""Return libxml2 doc for HTMLs"""
|
||||
utf8body = body_as_utf8(response)
|
||||
utf8body = body_as_utf8(response) or ' '
|
||||
try:
|
||||
lxdoc = libxml2.htmlReadDoc(utf8body, response.url, 'utf-8', \
|
||||
html_parser_options)
|
||||
|
|
@ -35,7 +35,7 @@ def xmlDoc_from_html(response):
|
|||
|
||||
def xmlDoc_from_xml(response):
|
||||
"""Return libxml2 doc for XMLs"""
|
||||
utf8body = body_as_utf8(response)
|
||||
utf8body = body_as_utf8(response) or ' '
|
||||
try:
|
||||
lxdoc = libxml2.readDoc(utf8body, response.url, 'utf-8', \
|
||||
xml_parser_options)
|
||||
|
|
|
|||
|
|
@ -241,6 +241,12 @@ class XPathSelectorTestCase(unittest.TestCase):
|
|||
u'\n ',
|
||||
u'\n pff\n'])
|
||||
|
||||
@libxml2debug
|
||||
def test_empty_bodies(self):
|
||||
r1 = TextResponse('http://www.example.com', body='')
|
||||
hxs = HtmlXPathSelector(r1) # shouldn't raise error
|
||||
xxs = XmlXPathSelector(r1) # shouldn't raise error
|
||||
|
||||
@libxml2debug
|
||||
def test_weakref_slots(self):
|
||||
"""Check that classes are using slots and are weak-referenceable"""
|
||||
|
|
|
|||
Loading…
Reference in New Issue