This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
The following commit(s) were added to refs/heads/master by this push:
new f264fc7 [#8383] strip bad unicode chars from /activity/feed.rss
f264fc7 is described below
commit f264fc70743d704e88d6ea2297353b3b842eb7ce
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 7e15aeb..8773279 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -160,6 +160,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 981fcaa..3b668c8 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\t\n\rfoo bar\x1E'
+ outputsample = 'HelloWorld\t\n\rfoo bar'
+ 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))