Skip to content

Commit 79c7081

Browse files
authored
* fix: Correctly urlize bis documents
The old code would first substitute the "rfx<nnnn>" part, and then again on the full draft name. This now only ever applies one substitute, and does longer ones first.
1 parent 966e1c8 commit 79c7081

2 files changed

Lines changed: 34 additions & 10 deletions

File tree

ietf/doc/templatetags/ietf_filters.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,12 @@ def urlize_ietf_docs(string, autoescape=None):
192192
"""
193193
if autoescape and not isinstance(string, SafeData):
194194
string = escape(string)
195-
string = re.sub(r"(RFC\s*?)0{0,3}(\d+)", "<a href=\"/doc/rfc\\2/\">\\1\\2</a>", string, flags=re.IGNORECASE)
196-
string = re.sub(r"(BCP\s*?)0{0,3}(\d+)", "<a href=\"/doc/bcp\\2/\">\\1\\2</a>", string, flags=re.IGNORECASE)
197-
string = re.sub(r"(STD\s*?)0{0,3}(\d+)", "<a href=\"/doc/std\\2/\">\\1\\2</a>", string, flags=re.IGNORECASE)
198-
string = re.sub(r"(FYI\s*?)0{0,3}(\d+)", "<a href=\"/doc/fyi\\2/\">\\1\\2</a>", string, flags=re.IGNORECASE)
199-
string = re.sub(r"(draft-[-0-9a-zA-Z._+]+)", "<a href=\"/doc/\\1/\">\\1</a>", string, flags=re.IGNORECASE)
200-
string = re.sub(r"(bofreq-[-0-9a-zA-Z._+]+)", "<a href=\"/doc/\\1/\">\\1</a>", string, flags=re.IGNORECASE)
201-
string = re.sub(r"(conflict-review-[-0-9a-zA-Z._+]+)", "<a href=\"/doc/\\1/\">\\1</a>", string, flags=re.IGNORECASE)
202-
string = re.sub(r"(status-change-[-0-9a-zA-Z._+]+)", "<a href=\"/doc/\\1/\">\\1</a>", string, flags=re.IGNORECASE)
203-
string = re.sub(r"(charter-[-0-9a-zA-Z._+]+)", "<a href=\"/doc/\\1/\">\\1</a>", string, flags=re.IGNORECASE)
195+
string = re.sub(
196+
r"\b((RFC|BCP|STD|FYI|(?:draft-|bofreq-|conflict-review-|status-change-|charter-)[-\d\w.+]+)\s*0*(\d+))\b",
197+
lambda x: f'<a href="/doc/{x[2].strip().lower()}{x[3]}/">{x[1]}</a>',
198+
string,
199+
flags=re.IGNORECASE | re.ASCII,
200+
)
204201
return mark_safe(string)
205202
urlize_ietf_docs = stringfilter(urlize_ietf_docs)
206203

@@ -739,4 +736,4 @@ def absurl(viewname, **kwargs):
739736
740737
Uses settings.IDTRACKER_BASE_URL as the base.
741738
"""
742-
return urljoin(settings.IDTRACKER_BASE_URL, urlreverse(viewname, kwargs=kwargs))
739+
return urljoin(settings.IDTRACKER_BASE_URL, urlreverse(viewname, kwargs=kwargs))
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from ietf.doc.templatetags.ietf_filters import urlize_ietf_docs
2+
from ietf.utils.test_utils import TestCase
3+
4+
# TODO: most other filters need test cases, too
5+
6+
7+
class IetfFiltersTests(TestCase):
8+
def test_urlize_ietf_docs(self):
9+
cases = [
10+
("no change", "no change"),
11+
("bcp1", '<a href="/doc/bcp1/">bcp1</a>'),
12+
("Std 003", '<a href="/doc/std3/">Std 003</a>'),
13+
(
14+
"FYI02 changes Std 003",
15+
'<a href="/doc/fyi2/">FYI02</a> changes <a href="/doc/std3/">Std 003</a>',
16+
),
17+
("rfc2119", '<a href="/doc/rfc2119/">rfc2119</a>'),
18+
("Rfc 02119", '<a href="/doc/rfc2119/">Rfc 02119</a>'),
19+
("draft-abc-123", '<a href="/doc/draft-abc-123/">draft-abc-123</a>'),
20+
(
21+
"draft-ietf-rfc9999-bis-01",
22+
'<a href="/doc/draft-ietf-rfc9999-bis-01/">draft-ietf-rfc9999-bis-01</a>',
23+
),
24+
]
25+
26+
for input, output in cases:
27+
self.assertEqual(urlize_ietf_docs(input), output)

0 commit comments

Comments
 (0)