Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

migrations: Remove filter_format_validator.

Zixuan James Li6f42542320aa
diff --git a/tools/semgrep.yml b/tools/semgrep.yml
index 5f928c4279e..51bb15991cd 100644
--- a/tools/semgrep.yml
+++ b/tools/semgrep.yml
@@ -21,7 +21,6 @@ rules:
patterns:
- pattern-not: from zerver.lib.redis_utils import get_redis_client
- pattern-not: from zerver.models import filter_pattern_validator
- - pattern-not: from zerver.models import filter_format_validator
- pattern-not: from zerver.models import url_template_validator
- pattern-not: from zerver.models import generate_email_token_for_stream
- pattern-either:
diff --git a/zerver/migrations/0094_realm_filter_url_validator.py b/zerver/migrations/0094_realm_filter_url_validator.py
index 68fca502f3c..3b9962d158c 100644
--- a/zerver/migrations/0094_realm_filter_url_validator.py
+++ b/zerver/migrations/0094_realm_filter_url_validator.py
@@ -1,7 +1,8 @@
# Generated by Django 1.11.2 on 2017-07-22 13:44
-from django.db import migrations, models
-from zerver.models import filter_format_validator
+from typing import List
+
+from django.db import migrations
class Migration(migrations.Migration):
@@ -9,10 +10,4 @@ class Migration(migrations.Migration):
("zerver", "0093_subscription_event_log_backfill"),
]
- operations = [
- migrations.AlterField(
- model_name="realmfilter",
- name="url_format_string",
- field=models.TextField(validators=[filter_format_validator]),
- ),
- ]
+ operations: List[migrations.operations.base.Operation] = []
diff --git a/zerver/migrations/0440_realmfilter_url_template.py b/zerver/migrations/0440_realmfilter_url_template.py
index dd19715193e..6f714d47dee 100644
--- a/zerver/migrations/0440_realmfilter_url_template.py
+++ b/zerver/migrations/0440_realmfilter_url_template.py
@@ -2,7 +2,7 @@
from django.db import migrations, models
-from zerver.models import filter_format_validator, url_template_validator
+from zerver.models import url_template_validator
class Migration(migrations.Migration):
@@ -19,6 +19,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name="realmfilter",
name="url_format_string",
- field=models.TextField(validators=[filter_format_validator], null=True, blank=True),
+ field=models.TextField(null=True, blank=True),
),
]
diff --git a/zerver/models.py b/zerver/models.py
index d45521e5a78..b320779919a 100644
--- a/zerver/models.py
+++ b/zerver/models.py
@@ -1,5 +1,4 @@
import datetime
-import re
import secrets
import time
from contextlib import suppress
@@ -1266,39 +1265,6 @@ def filter_pattern_validator(value: str) -> Pattern[str]:
return regex
-def filter_format_validator(value: str) -> None:
- """Verifies URL-ness, and then %(foo)s.
-
- URLValidator is assumed to catch anything which is malformed as a
- URL; the regex then verifies the format-string pieces.
- """
-
- URLValidator()(value)
-
- regex = re.compile(
- r"""
- ^
- (
- [^%] # Any non-percent,
- | # OR...
- % ( # A %, which can mean:
- \( [a-zA-Z0-9_-]+ \) s # Interpolation group
- | # OR
- % # %%, which is an escaped %
- | # OR
- [0-9a-fA-F][0-9a-fA-F] # URL percent-encoded bytes, which we
- # special-case in markdown translation
- )
- )+ # Those happen one or more times
- $
- """,
- re.VERBOSE,
- )
-
- if not regex.match(value):
- raise ValidationError(_("Invalid format string in URL."))
-
-
def url_template_validator(value: str) -> None:
"""Validate as a URL template"""
if not uri_template.validate(value):