Skip to content

Commit

Permalink
Fixed CHARSET_RE to parse encoding also form header without white spa…
Browse files Browse the repository at this point in the history
…ce between type and charset.
  • Loading branch information
datakurre committed Dec 27, 2012
1 parent 346d943 commit db6faec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions plone/transformchain/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,23 @@ def __call__(self, request, result, encoding):

self.assertEquals("dummy", transformer.encoding)

def test_applyTransform_other_encoding_with_header_missing_space(self):
class EncodingCaptureTransformer(object):
implements(ITransformer)
encoding = None
def __call__(self, request, result, encoding):
self.encoding = encoding

transformer = EncodingCaptureTransformer()
provideUtility(transformer)

published = FauxPublished()
request = FauxRequest(published)
request.response.headers['content-type'] = 'text/html;charset=dummy'
applyTransformOnSuccess(FauxPubEvent(request))

self.assertEquals("dummy", transformer.encoding)

def test_applyTransform_str(self):
class FauxTransformer(object):
implements(ITransformer)
Expand Down
2 changes: 1 addition & 1 deletion plone/transformchain/zpublisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class IPubBeforeAbort(Interface):
pass

CHARSET_RE = re.compile(r'(?:application|text)/[-+0-9a-z]+\s*;\scharset=([-_0-9a-z]+)(?:(?:\s*;)|\Z)', re.IGNORECASE)
CHARSET_RE = re.compile(r'(?:application|text)/[-+0-9a-z]+\s*;\s?charset=([-_0-9a-z]+)(?:(?:\s*;)|\Z)', re.IGNORECASE)

def extractEncoding(response):
"""Get the content encoding for the response body
Expand Down

0 comments on commit db6faec

Please sign in to comment.