diff --git a/zerver/models.py b/zerver/models.py index f0235dd6e1..44ff2f7ec5 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -656,7 +656,7 @@ def filter_pattern_validator(value: str) -> None: raise ValidationError(error_msg) def filter_format_validator(value: str) -> None: - regex = re.compile(r'^([\.\/:a-zA-Z0-9#_?=-]+%\(([a-zA-Z0-9_-]+)\)s)+[a-zA-Z0-9_-]*$') + regex = re.compile(r'^([\.\/:a-zA-Z0-9#_?=&-]+%\(([a-zA-Z0-9_-]+)\)s)+[/a-zA-Z0-9#_?=&-]*$') if not regex.match(value): raise ValidationError(_('Invalid URL format string.')) diff --git a/zerver/tests/test_realm_filters.py b/zerver/tests/test_realm_filters.py index 93d41bcbaa..5916722d12 100644 --- a/zerver/tests/test_realm_filters.py +++ b/zerver/tests/test_realm_filters.py @@ -58,25 +58,25 @@ class RealmFilterTest(ZulipTestCase): self.assertIsNotNone(re.match(data['pattern'], 'ZUL2-15')) data['pattern'] = r'_code=(?P[0-9a-zA-Z]+)' - data['url_format_string'] = 'https://realm.com/my_realm_filter/?value=%(id)s' + data['url_format_string'] = 'https://example.com/product/%(id)s/details' result = self.client_post("/json/realm/filters", info=data) self.assert_json_success(result) self.assertIsNotNone(re.match(data['pattern'], '_code=123abcdZ')) data['pattern'] = r'PR (?P[0-9]+)' - data['url_format_string'] = 'https://realm.com/my_realm_filter/?value=%(id)s' + data['url_format_string'] = 'https://example.com/web#view_type=type&model=model&action=12345&id=%(id)s' result = self.client_post("/json/realm/filters", info=data) self.assert_json_success(result) self.assertIsNotNone(re.match(data['pattern'], 'PR 123')) data['pattern'] = r'lp/(?P[0-9]+)' - data['url_format_string'] = 'https://realm.com/my_realm_filter/?value=%(id)s' + data['url_format_string'] = 'https://realm.com/my_realm_filter/?value=%(id)s&sort=reverse' result = self.client_post("/json/realm/filters", info=data) self.assert_json_success(result) self.assertIsNotNone(re.match(data['pattern'], 'lp/123')) data['pattern'] = r'lp:(?P[0-9]+)' - data['url_format_string'] = 'https://realm.com/my_realm_filter/?value=%(id)s' + data['url_format_string'] = 'https://realm.com/my_realm_filter/?sort=reverse&value=%(id)s' result = self.client_post("/json/realm/filters", info=data) self.assert_json_success(result) self.assertIsNotNone(re.match(data['pattern'], 'lp:123'))