refactor: Update some uses of "filter" to "linkifier".

This updates some comments and local variables
which could be changed without breaking other
stuff.
This commit is contained in:
Abhijeet Prasad Bodas 2021-03-30 15:38:03 +05:30 committed by Tim Abbott
parent a49dc67d8e
commit f896a7667f
7 changed files with 41 additions and 41 deletions

View File

@ -50,7 +50,7 @@ async function test_invalid_linkifier_pattern(page: Page): Promise<void> {
await page.waitForSelector("div#admin-linkifier-pattern-status", {visible: true});
assert.strictEqual(
await common.get_text_from_selector(page, "div#admin-linkifier-pattern-status"),
"Failed: Invalid filter pattern. Valid characters are [ a-zA-Z_#=/:+!-].",
"Failed: Invalid linkifier pattern. Valid characters are [ a-zA-Z_#=/:+!-].",
);
}

View File

@ -6505,12 +6505,12 @@ def notify_realm_filters(realm: Realm) -> None:
def do_add_realm_filter(realm: Realm, pattern: str, url_format_string: str) -> int:
pattern = pattern.strip()
url_format_string = url_format_string.strip()
realm_filter = RealmFilter(realm=realm, pattern=pattern, url_format_string=url_format_string)
realm_filter.full_clean()
realm_filter.save()
linkifier = RealmFilter(realm=realm, pattern=pattern, url_format_string=url_format_string)
linkifier.full_clean()
linkifier.save()
notify_realm_filters(realm)
return realm_filter.id
return linkifier.id
def do_remove_realm_filter(

View File

@ -1781,7 +1781,7 @@ OUTER_CAPTURE_GROUP = "linkifier_actual_match"
def prepare_realm_pattern(source: str) -> str:
"""Augment a realm filter so it only matches after start-of-string,
"""Augment a linkifier so it only matches after start-of-string,
whitespace, or opening delimiters, won't match if there are word
characters directly after, and saves what was matched as
OUTER_CAPTURE_GROUP."""
@ -2059,7 +2059,7 @@ class LinkInlineProcessor(markdown.inlinepatterns.LinkInlineProcessor):
if not el.text or not el.text.strip():
el.text = href
# Prevent realm_filters from running on the content of a Markdown link, breaking up the link.
# Prevent linkifiers from running on the content of a Markdown link, breaking up the link.
# This is a monkey-patch, but it might be worth sending a version of this change upstream.
el.text = markdown.util.AtomicString(el.text)
@ -2633,7 +2633,7 @@ def do_convert(
# Spend at most 5 seconds rendering; this protects the backend
# from being overloaded by bugs (e.g. Markdown logic that is
# extremely inefficient in corner cases) as well as user
# errors (e.g. a realm filter that makes some syntax
# errors (e.g. a linkifier that makes some syntax
# infinite-loop).
rendered_content = timeout(5, lambda: _md_engine.convert(content))

View File

@ -849,7 +849,7 @@ post_delete.connect(flush_realm_emoji, sender=RealmEmoji)
def filter_pattern_validator(value: str) -> None:
regex = re.compile(r"^(?:(?:[\w\-#_= /:]*|[+]|[!])(\(\?P<\w+>.+\)))+$")
error_msg = _("Invalid filter pattern. Valid characters are {}.").format(
error_msg = _("Invalid linkifier pattern. Valid characters are {}.").format(
"[ a-zA-Z_#=/:+!-]",
)

View File

@ -1257,12 +1257,12 @@ class MarkdownTest(ZulipTestCase):
def test_realm_patterns(self) -> None:
realm = get_realm("zulip")
url_format_string = r"https://trac.example.com/ticket/%(id)s"
realm_filter = RealmFilter(
linkifier = RealmFilter(
realm=realm, pattern=r"#(?P<id>[0-9]{2,8})", url_format_string=url_format_string
)
realm_filter.save()
linkifier.save()
self.assertEqual(
realm_filter.__str__(),
linkifier.__str__(),
"<RealmFilter(zulip): #(?P<id>[0-9]{2,8}) https://trac.example.com/ticket/%(id)s>",
)
@ -1368,27 +1368,27 @@ class MarkdownTest(ZulipTestCase):
def test_multiple_matching_realm_patterns(self) -> None:
realm = get_realm("zulip")
url_format_string = r"https://trac.example.com/ticket/%(id)s"
realm_filter_1 = RealmFilter(
linkifier_1 = RealmFilter(
realm=realm,
pattern=r"(?P<id>ABC\-[0-9]+)(?![A-Z0-9-])",
url_format_string=url_format_string,
)
realm_filter_1.save()
linkifier_1.save()
self.assertEqual(
realm_filter_1.__str__(),
linkifier_1.__str__(),
r"<RealmFilter(zulip): (?P<id>ABC\-[0-9]+)(?![A-Z0-9-])"
" https://trac.example.com/ticket/%(id)s>",
)
url_format_string = r"https://other-trac.example.com/ticket/%(id)s"
realm_filter_2 = RealmFilter(
linkifier_2 = RealmFilter(
realm=realm,
pattern=r"(?P<id>[A-Z][A-Z0-9]*\-[0-9]+)(?![A-Z0-9-])",
url_format_string=url_format_string,
)
realm_filter_2.save()
linkifier_2.save()
self.assertEqual(
realm_filter_2.__str__(),
linkifier_2.__str__(),
r"<RealmFilter(zulip): (?P<id>[A-Z][A-Z0-9]*\-[0-9]+)(?![A-Z0-9-])"
" https://other-trac.example.com/ticket/%(id)s>",
)
@ -1404,8 +1404,8 @@ class MarkdownTest(ZulipTestCase):
converted = markdown_convert(content, message_realm=realm, message=msg)
converted_topic = topic_links(realm.id, msg.topic_name())
# The second filter (which was saved later) was ignored as the content was marked AtomicString after first conversion.
# There was no easy way to support parsing both filters and not run into an infinite loop, hence the second filter is ignored.
# The second linkifier (which was saved later) was ignored as the content was marked AtomicString after first conversion.
# There was no easy way to support parsing both linkifiers and not run into an infinite loop, hence the second linkifier is ignored.
self.assertEqual(
converted,
'<p>We should fix <a href="https://trac.example.com/ticket/ABC-123">ABC-123</a> or <a href="https://trac.example.com/ticket/16">trac ABC-123</a> today.</p>',
@ -1422,10 +1422,10 @@ class MarkdownTest(ZulipTestCase):
def test_maybe_update_markdown_engines(self) -> None:
realm = get_realm("zulip")
url_format_string = r"https://trac.example.com/ticket/%(id)s"
realm_filter = RealmFilter(
linkifier = RealmFilter(
realm=realm, pattern=r"#(?P<id>[0-9]{2,8})", url_format_string=url_format_string
)
realm_filter.save()
linkifier.save()
import zerver.lib.markdown
@ -1436,10 +1436,10 @@ class MarkdownTest(ZulipTestCase):
self.assertEqual(len(zulip_filters), 1)
self.assertEqual(
zulip_filters[0],
("#(?P<id>[0-9]{2,8})", "https://trac.example.com/ticket/%(id)s", realm_filter.id),
("#(?P<id>[0-9]{2,8})", "https://trac.example.com/ticket/%(id)s", linkifier.id),
)
def test_flush_realm_filter(self) -> None:
def test_flush_linkifier(self) -> None:
realm = get_realm("zulip")
def flush() -> None:
@ -2083,12 +2083,12 @@ class MarkdownTest(ZulipTestCase):
msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
# Create a linkifier.
url_format_string = r"https://trac.example.com/ticket/%(id)s"
realm_filter = RealmFilter(
linkifier = RealmFilter(
realm=realm, pattern=r"#(?P<id>[0-9]{2,8})", url_format_string=url_format_string
)
realm_filter.save()
linkifier.save()
self.assertEqual(
realm_filter.__str__(),
linkifier.__str__(),
"<RealmFilter(zulip): #(?P<id>[0-9]{2,8}) https://trac.example.com/ticket/%(id)s>",
)
# Create a user that potentially interferes with the pattern.
@ -2167,12 +2167,12 @@ class MarkdownTest(ZulipTestCase):
user_profile = self.example_user("hamlet")
# Create a linkifier.
url_format_string = r"https://trac.example.com/ticket/%(id)s"
realm_filter = RealmFilter(
linkifier = RealmFilter(
realm=realm, pattern=r"#(?P<id>[0-9]{2,8})", url_format_string=url_format_string
)
realm_filter.save()
linkifier.save()
self.assertEqual(
realm_filter.__str__(),
linkifier.__str__(),
"<RealmFilter(zulip): #(?P<id>[0-9]{2,8}) https://trac.example.com/ticket/%(id)s>",
)
# Create a user-group that potentially interferes with the pattern.
@ -2361,12 +2361,12 @@ class MarkdownTest(ZulipTestCase):
# Create a linkifier.
sender_user_profile = self.example_user("othello")
url_format_string = r"https://trac.example.com/ticket/%(id)s"
realm_filter = RealmFilter(
linkifier = RealmFilter(
realm=realm, pattern=r"#(?P<id>[0-9]{2,8})", url_format_string=url_format_string
)
realm_filter.save()
linkifier.save()
self.assertEqual(
realm_filter.__str__(),
linkifier.__str__(),
"<RealmFilter(zulip): #(?P<id>[0-9]{2,8}) https://trac.example.com/ticket/%(id)s>",
)
# Create a topic link that potentially interferes with the pattern.
@ -2430,12 +2430,12 @@ class MarkdownTest(ZulipTestCase):
# Create a linkifier.
sender_user_profile = self.example_user("othello")
url_format_string = r"https://trac.example.com/ticket/%(id)s"
realm_filter = RealmFilter(
linkifier = RealmFilter(
realm=realm, pattern=r"#(?P<id>[0-9]{2,8})", url_format_string=url_format_string
)
realm_filter.save()
linkifier.save()
self.assertEqual(
realm_filter.__str__(),
linkifier.__str__(),
"<RealmFilter(zulip): #(?P<id>[0-9]{2,8}) https://trac.example.com/ticket/%(id)s>",
)
# Create a stream that potentially interferes with the pattern.

View File

@ -249,11 +249,11 @@ class MessageDictTest(ZulipTestCase):
links = {"url": "https://trac.example.com/ticket/123", "text": "#123"}
topic_name = "test #123"
realm_filter = RealmFilter(
linkifier = RealmFilter(
realm=zulip_realm, pattern=r"#(?P<id>[0-9]{2,8})", url_format_string=url_format_string
)
self.assertEqual(
realm_filter.__str__(),
linkifier.__str__(),
"<RealmFilter(zulip): #(?P<id>[0-9]{2,8}) https://trac.example.com/ticket/%(id)s>",
)
@ -271,7 +271,7 @@ class MessageDictTest(ZulipTestCase):
assert_topic_links([], get_message(self.example_user("othello")))
assert_topic_links([], get_message(self.lear_user("cordelia")))
assert_topic_links([], get_message(self.notification_bot()))
realm_filter.save()
linkifier.save()
assert_topic_links([links], get_message(self.example_user("othello")))
assert_topic_links([links], get_message(self.lear_user("cordelia")))
assert_topic_links([links], get_message(self.notification_bot()))

View File

@ -24,13 +24,13 @@ class RealmFilterTest(ZulipTestCase):
data["pattern"] = "$a"
result = self.client_post("/json/realm/filters", info=data)
self.assert_json_error(
result, "Invalid filter pattern. Valid characters are [ a-zA-Z_#=/:+!-]."
result, "Invalid linkifier pattern. Valid characters are [ a-zA-Z_#=/:+!-]."
)
data["pattern"] = r"ZUL-(?P<id>\d++)"
result = self.client_post("/json/realm/filters", info=data)
self.assert_json_error(
result, "Invalid filter pattern. Valid characters are [ a-zA-Z_#=/:+!-]."
result, "Invalid linkifier pattern. Valid characters are [ a-zA-Z_#=/:+!-]."
)
data["pattern"] = r"ZUL-(?P<id>\d+)"