mirror of https://github.com/zulip/zulip.git
realm filters: Make validation error messages more useful.
This commit is contained in:
parent
34e39248fc
commit
c87a533b3b
|
@ -565,7 +565,8 @@ 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, you must use the following format OPTIONAL_PREFIX(?P<id>.+)'
|
||||
error_msg = _('Invalid filter pattern. Valid characters are %s.' % (
|
||||
'[ a-zA-Z_#=/:+!-]',))
|
||||
|
||||
if not regex.match(str(value)):
|
||||
raise ValidationError(error_msg)
|
||||
|
@ -580,8 +581,7 @@ def filter_format_validator(value: str) -> None:
|
|||
regex = re.compile(r'^([\.\/:a-zA-Z0-9#_?=-]+%\(([a-zA-Z0-9_-]+)\)s)+[a-zA-Z0-9_-]*$')
|
||||
|
||||
if not regex.match(value):
|
||||
raise ValidationError('URL format string must be in the following format: '
|
||||
r'`https://example.com/%(\w+)s`')
|
||||
raise ValidationError(_('Invalid URL format string.'))
|
||||
|
||||
class RealmFilter(models.Model):
|
||||
"""Realm-specific regular expressions to automatically linkify certain
|
||||
|
|
|
@ -30,11 +30,11 @@ class RealmFilterTest(ZulipTestCase):
|
|||
|
||||
data['pattern'] = '$a'
|
||||
result = self.client_post("/json/realm/filters", info=data)
|
||||
self.assert_json_error(result, 'Invalid filter pattern, you must use the following format OPTIONAL_PREFIX(?P<id>.+)')
|
||||
self.assert_json_error(result, 'Invalid filter 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, you must use the following format OPTIONAL_PREFIX(?P<id>.+)')
|
||||
self.assert_json_error(result, 'Invalid filter pattern. Valid characters are [ a-zA-Z_#=/:+!-].')
|
||||
|
||||
data['pattern'] = r'ZUL-(?P<id>\d+)'
|
||||
data['url_format_string'] = '$fgfg'
|
||||
|
@ -44,7 +44,7 @@ class RealmFilterTest(ZulipTestCase):
|
|||
data['pattern'] = r'ZUL-(?P<id>\d+)'
|
||||
data['url_format_string'] = 'https://realm.com/my_realm_filter/'
|
||||
result = self.client_post("/json/realm/filters", info=data)
|
||||
self.assert_json_error(result, 'URL format string must be in the following format: `https://example.com/%(\\w+)s`')
|
||||
self.assert_json_error(result, 'Invalid URL format string.')
|
||||
|
||||
data['url_format_string'] = 'https://realm.com/my_realm_filter/#hashtag/%(id)s'
|
||||
result = self.client_post("/json/realm/filters", info=data)
|
||||
|
|
Loading…
Reference in New Issue