You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by di...@apache.org on 2026/04/29 22:02:24 UTC
(allura) 01/02: fixup! [#8602] do not treat periods in text as external urls to be displayed as warnings
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch dw/8602
in repository https://gitbox.apache.org/repos/asf/allura.git
commit d12e60e05957038d92013858c108bb0abe267836
Author: Dillon Walls <di...@slashdotmedia.com>
AuthorDate: Wed Apr 29 22:01:25 2026 +0000
fixup! [#8602] do not treat periods in text as external urls to be displayed as warnings
---
Allura/allura/lib/utils.py | 4 ++--
Allura/allura/tests/test_utils.py | 33 +++++++++++++++++++++++++++------
2 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index 3f332923d..a7b416be8 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -768,10 +768,10 @@ def text_contains_any_url(text: str) -> bool:
candidate = token.strip('\'"[]{}()<>,;!?')
if not candidate or ('@' in candidate and '://' not in candidate):
continue
- if '://' in candidate:
+ if '://' in candidate or candidate.startswith('//'):
if urlparse(candidate).hostname:
return True
- elif '.' in candidate and re.search(r'[a-zA-Z]{2,}\.[a-zA-Z]{2,}([/?]|$)', candidate):
+ elif '.' in candidate and re.search(r'[a-zA-Z0-9-]{2,}\.[a-zA-Z]{2,}([/?]|$)', candidate):
if urlparse('//' + candidate).hostname:
return True
return False
diff --git a/Allura/allura/tests/test_utils.py b/Allura/allura/tests/test_utils.py
index b03548247..0d88dde95 100644
--- a/Allura/allura/tests/test_utils.py
+++ b/Allura/allura/tests/test_utils.py
@@ -329,6 +329,10 @@ def test_misleading_links(self):
assert (self.sanitize_html('<a href="/p/local/wiki/">example.com</a>') ==
'<a href="/p/local/wiki/">example.com</a>')
+ # SUFFIX: sub domain
+ assert (self.sanitize_html('<a href="http://sub.evil.com/">visit example.com for more</a>') ==
+ '<a href="http://sub.evil.com/">visit example.com for more</a> (sub.evil.com)')
+
# SUFFIX: mismatch domain embedded in a longer sentence
assert (self.sanitize_html('<a href="http://evil.com/">visit example.com for more</a>') ==
'<a href="http://evil.com/">visit example.com for more</a> (evil.com)')
@@ -383,19 +387,36 @@ def test_misleading_links_idn(self):
'<a href="http://中文.com/">中文.com</a>')
-def test_text_contains_any_url():
- assert utils.text_contains_any_url('example.com') is True
- assert utils.text_contains_any_url('foo a1-2-3.space bar') is True
- assert utils.text_contains_any_url('click here') is False
+@pytest.mark.parametrize('text, expected', [
+ ('example.com', True),
+ ('foo a1-2-3.space bar', True),
+ ('click here', False),
+ ('https://example.com/', True),
+ ('word https://example.com/', True),
+ ('word https://example.com/?foo=bar', True),
+ ('word https://example.com?foo=bar', True),
+ ('word https://example.com/with/path', True),
+ ('wordhttps://example.com/with/path', True),
+ ('word //example.com/with/path', True),
+ ('word //example.com/with/path?foo', True),
+ ('word//example.com/with/path?foo', True),
+ ('word example.com/with/path?foo', True),
+ ('sub.sub.example.com/with/path?foo', True),
+ ('word sub.sub.example.com/with/path?foo', True),
# false positives: file extensions and library names with dots parse as hostnames
- assert utils.text_contains_any_url('README.md') is True # .md suffix
- assert utils.text_contains_any_url('Node.js') is True # .js suffix
+ ('README.md', True), # .md suffix
+ ('Node.js', True), # .js suffix
+])
+def test_text_contains_any_url(text, expected):
+ assert utils.text_contains_any_url(text) is expected
def test_text_contains_hostname():
assert utils.text_contains_hostname('visit example.com for info', 'example.com') is True
assert utils.text_contains_hostname('visit example.com for info', 'example.comevil.org') is False
assert utils.text_contains_hostname('click here', 'example.com') is False
+ assert utils.text_contains_hostname('visit sub.example.com for info', 'sub.example.com') is True
+ assert utils.text_contains_hostname('visit example.com/path/ for info', 'example.com') is True
def test_ip_address():