Commit 4b29fcf0 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

handle original character set.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41862 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 26894651
......@@ -164,8 +164,10 @@ class StrippingParser(HTMLParser):
def handle_data(self, data):
if self.suppress: return
if data:
self.result.append(escape(data))
data = escape(data)
if self.original_charset and isinstance(data, str):
data = data.decode(self.original_charset)
self.result.append(data)
def handle_charref(self, name):
if self.suppress: return
......@@ -252,6 +254,8 @@ class StrippingParser(HTMLParser):
k = len(self.rawdata)
data = self.rawdata[i+9:k]
j = k+3
if self.original_charset and isinstance(data, str):
data = data.decode(self.original_charset)
self.result.append("<![CDATA[%s]]>" % data)
else:
try:
......@@ -278,11 +282,10 @@ def scrubHTML(html, valid=VALID_TAGS, nasty=NASTY_TAGS,
default_encoding=default_encoding)
parser.feed(html)
parser.close()
if parser.original_charset:
result = parser.getResult().decode(parser.original_charset)\
.encode(default_encoding)
return result
return parser.getResult()
result = parser.getResult()
if parser.original_charset and isinstance(result, str):
result = result.decode(parser.original_charset).encode(default_encoding)
return result
class SafeHTML:
"""Simple transform which uses CMFDefault functions to
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment