meta tag attributes for content-type http equiv can be in any order. #123

This commit is contained in:
Daniel Graña 2012-04-27 01:04:00 -03:00
parent 4d17048ac2
commit 0cb68afe7e
2 changed files with 11 additions and 2 deletions

View File

@ -18,7 +18,7 @@ class HtmlResponse(TextResponse):
_content_re = _template % ('content', r'(?P<mime>[^;]+);\s*charset=(?P<charset>[\w-]+)')
_content2_re = _template % ('charset', r'(?P<charset>[\w-]+)')
METATAG_RE = re.compile(r'<meta\s+%s\s+%s' % (_httpequiv_re, _content_re), re.I)
METATAG_RE = re.compile(r'<meta(?:\s+(?:%s|%s)){2}' % (_httpequiv_re, _content_re), re.I)
METATAG2_RE = re.compile(r'<meta\s+%s' % _content2_re, re.I)
@memoizemethod_noargs

View File

@ -226,7 +226,6 @@ class HtmlResponseTest(TextResponseTest):
response_class = HtmlResponse
def test_html_encoding(self):
body = """<html><head><title>Some page</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head><body>Price: \xa3100</body></html>'
"""
@ -257,6 +256,16 @@ class HtmlResponseTest(TextResponseTest):
r1 = self.response_class("http://www.example.com", body=body)
self._assert_response_values(r1, 'gb2312', body)
def test_httpequiv_meta(self):
body = '''<html><head><meta content="text/html; charset=gb18030" http-equiv="Content-Type" /></head></html>'''
response = self.response_class('http://example.com', body=body)
self._assert_response_values(response, 'gb18030', body)
body = '''<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb18030" /></head></html>'''
response = self.response_class('http://example.com', body=body)
self._assert_response_values(response, 'gb18030', body)
class XmlResponseTest(TextResponseTest):