allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [allura] 09/16: [#8375] hide_private_info Markup py3 fix
Date Thu, 27 Aug 2020 20:35:34 GMT
This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch db/8375
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 8c27232091819e056b60d035ee049281c302ae56
Author: Dave Brondsema <dave@brondsema.net>
AuthorDate: Tue Aug 25 17:00:44 2020 -0400

    [#8375] hide_private_info Markup py3 fix
---
 Allura/allura/lib/helpers.py        | 6 +++++-
 Allura/allura/tests/test_helpers.py | 3 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index 1bcff39..fd660ad 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -1271,7 +1271,11 @@ email_re = re.compile(r'(([a-z0-9_]|\-|\.)+)@([\w\.-]+)', re.IGNORECASE)
 
 def hide_private_info(message):
     if asbool(tg.config.get('hide_private_info', 'true')) and message:
-        return email_re.sub(r'\1@...', message)
+        hidden = email_re.sub(r'\1@...', message)
+        if type(message) not in six.string_types:
+            # custom subclass like markupsafe.Markup, convert to that type again
+            hidden = type(message)(hidden)
+        return hidden
     else:
         return message
 
diff --git a/Allura/allura/tests/test_helpers.py b/Allura/allura/tests/test_helpers.py
index 4b84bce..0206b02 100644
--- a/Allura/allura/tests/test_helpers.py
+++ b/Allura/allura/tests/test_helpers.py
@@ -665,6 +665,9 @@ def test_hide_private_info():
     assert_equals(h.hide_private_info(''), '')
     assert_equals(h.hide_private_info('foo bar baz@bing.com'), 'foo bar baz@...')
     assert_equals(h.hide_private_info('some <1@2.com>\nor asdf+asdf.f@g.f.x'), 'some
<1@...>\nor asdf+asdf.f@...')
+    safe_markup_converted = h.hide_private_info(Markup('foo bar baz@bing.com'))
+    assert_equals(type(safe_markup_converted), Markup)
+    assert_equals(safe_markup_converted, Markup('foo bar baz@...'))
 
     with h.push_config(h.tg.config, hide_private_info=False):
         assert_equals(h.hide_private_info('foo bar baz@bing.com'), 'foo bar baz@bing.com')


Mime
View raw message