This is an automated email from the ASF dual-hosted git repository. dill0wn pushed a commit to branch dw/8383 in repository https://gitbox.apache.org/repos/asf/allura.git
commit 9610f089871eed357fb3c7b8375b846bc9522cdc Author: Dillon Walls <[email protected]> AuthorDate: Mon Dec 7 23:29:51 2020 +0000 8383 strip bad unicode chars from /activity/feed.rss --- Allura/allura/lib/helpers.py | 9 +++++++++ Allura/allura/tests/test_helpers.py | 7 +++++++ ForgeActivity/forgeactivity/main.py | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py index fd660ad..2f4d2f5 100644 --- a/Allura/allura/lib/helpers.py +++ b/Allura/allura/lib/helpers.py @@ -158,6 +158,15 @@ def escape_json(data): return json.dumps(data).replace('<', '\\u003C') +def strip_bad_unicode(s): + """ + xml doesn't like some control characters: https://www.w3.org/TR/REC-xml/#charsets + :param s: + :return: + """ + return re.sub('[\x00-\x08\x0B\x0C\x0E-\x1F]', '', s) + + def monkeypatch(*objs): def patchem(func): for obj in objs: diff --git a/Allura/allura/tests/test_helpers.py b/Allura/allura/tests/test_helpers.py index 0206b02..f6fc852 100644 --- a/Allura/allura/tests/test_helpers.py +++ b/Allura/allura/tests/test_helpers.py @@ -89,6 +89,13 @@ def test_escape_json(): assert_equals(outputdata, outputsample) +def test_strip_bad_unicode(): + inputdata = 'Hello\x08World' + outputsample = 'HelloWorld' + outputdata = h.strip_bad_unicode(inputdata) + assert_equals(outputdata, outputsample) + + def test_really_unicode(): here_dir = path.dirname(__file__) s = h.really_unicode(b'asdf') diff --git a/ForgeActivity/forgeactivity/main.py b/ForgeActivity/forgeactivity/main.py index 0ee91d5..4ca24c4 100644 --- a/ForgeActivity/forgeactivity/main.py +++ b/ForgeActivity/forgeactivity/main.py @@ -178,7 +178,7 @@ class ForgeActivityController(BaseController): ), link=url, pubdate=t.published, - description=t.obj.activity_extras.get('summary'), + description=h.strip_bad_unicode(t.obj.activity_extras.get('summary', '')), unique_id=url_id, author_name=t.actor.activity_name, author_link=h.absurl(t.actor.activity_url))
