You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2023/05/09 16:30:18 UTC
[allura] branch master updated: Escape colons in the registration_ip field for IPv6 addresses
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 bbd2d03d4 Escape colons in the registration_ip field for IPv6 addresses
bbd2d03d4 is described below
commit bbd2d03d4581fff8e86080c13ebb02cf6f16c068
Author: Carlos Cruz <ca...@slashdotmedia.com>
AuthorDate: Thu May 4 16:57:09 2023 +0000
Escape colons in the registration_ip field for IPv6 addresses
---
Allura/allura/lib/search.py | 2 ++
Allura/allura/tests/unit/test_solr.py | 5 +++++
2 files changed, 7 insertions(+)
diff --git a/Allura/allura/lib/search.py b/Allura/allura/lib/search.py
index a8ed6e58e..7dd375f18 100644
--- a/Allura/allura/lib/search.py
+++ b/Allura/allura/lib/search.py
@@ -215,6 +215,7 @@ def site_admin_search(model, q, field, **kw):
if obj is None:
return # if there are no objects, we won't find anything
fields = obj.index()
+
if field == '__custom__':
# custom query -> query as is
q = obj.translate_query(q, fields)
@@ -224,6 +225,7 @@ def site_admin_search(model, q, field, **kw):
# escaping spaces with '\ ' isn't sufficient for display_name_t since its stored as text_general (why??)
# and wouldn't handle foo@bar.com split on @ either
# This should work, but doesn't for unknown reasons: q = u'{!term f=%s}%s' % (field, q)
+ q = q.replace(':', '\:') # Must escape the colon for IPv6 addresses
q = obj.translate_query(f'{field}:({q})', fields)
kw['q.op'] = 'AND' # so that all terms within the () are required
fq = ['type_s:%s' % model.type_s]
diff --git a/Allura/allura/tests/unit/test_solr.py b/Allura/allura/tests/unit/test_solr.py
index 588830804..6ea6ca628 100644
--- a/Allura/allura/tests/unit/test_solr.py
+++ b/Allura/allura/tests/unit/test_solr.py
@@ -119,6 +119,11 @@ class TestSolr(unittest.TestCase):
search.assert_called_once_with(
'username_s:admin1 || username_s:root', fq=fq, ignore_errors=False)
+ search.reset_mock()
+ site_admin_search(User, '2601:404:c300:a560:598f:9336:d2bb:9e32', 'registration_ip')
+ search.assert_called_once_with(
+ 'registration_ip:(2601\:404\:c300\:a560\:598f\:9336\:d2bb\:9e32)', fq=fq, ignore_errors=False, **{'q.op': 'AND'})
+
class TestSearchIndexable(unittest.TestCase):