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 b53e27992 precompile a few regexes
b53e27992 is described below

commit b53e27992e40b48375f86985cac9fa44dde5d823
Author: Dave Brondsema <[email protected]>
AuthorDate: Tue Oct 7 09:35:02 2025 -0400

    precompile a few regexes
---
 Allura/allura/lib/helpers.py        | 5 ++++-
 ForgeActivity/forgeactivity/main.py | 8 +++++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index ef741f5de..92b3cb106 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -188,13 +188,16 @@ def ceil(number):
     return math.ceil(number)
 
 
+bad_unicode_re = re.compile(r'[\x00-\x08\x0B\x0C\x0E-\x1F]')
+
+
 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)
+    return bad_unicode_re.sub('', s)
 
 
 def monkeypatch(*objs):
diff --git a/ForgeActivity/forgeactivity/main.py 
b/ForgeActivity/forgeactivity/main.py
index 2a911a3c8..3cbe91dec 100644
--- a/ForgeActivity/forgeactivity/main.py
+++ b/ForgeActivity/forgeactivity/main.py
@@ -82,6 +82,9 @@ class W:
     page_list = PageList()
 
 
+old_default_avatar_re = re.compile(r'([&?])d=[^&]*')
+
+
 class ForgeActivityController(BaseController):
 
     def __init__(self, app, *args, **kw):
@@ -148,9 +151,8 @@ def _get_activities_data(self, **kw):
                     t.actor.activity_extras.icon_url = default_avatar
                 else:
                     # fix gravatar urls with old default avatar urls in them
-                    t.actor.activity_extras.icon_url = re.sub(r'([&?])d=[^&]*',
-                                                              
fr'\1d={default_avatar}',
-                                                              
t.actor.activity_extras.icon_url)
+                    t.actor.activity_extras.icon_url = 
old_default_avatar_re.sub(fr'\1d={default_avatar}',
+                                                                               
  t.actor.activity_extras.icon_url)
             if t.actor.activity_url:
                 t.actor.activity_url = f'{t.actor.activity_url}profile/'
 

Reply via email to