realm_filters: Allows more use of & and friends in URLs.

We had some excessively tight rules about what characters were
allowed, which in particular prevented using `?foo=bar&baz=quux`
structures in the realm filters URLs.

Fixes #12239.
This commit is contained in:
Tim Abbott
2019-05-13 13:28:17 -07:00
parent 2bb3af1ade
commit a4bf15bbc7
2 changed files with 5 additions and 5 deletions

View File

@@ -594,7 +594,7 @@ def filter_pattern_validator(value: str) -> None:
raise ValidationError(error_msg) raise ValidationError(error_msg)
def filter_format_validator(value: str) -> None: 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): if not regex.match(value):
raise ValidationError(_('Invalid URL format string.')) raise ValidationError(_('Invalid URL format string.'))

View File

@@ -58,25 +58,25 @@ class RealmFilterTest(ZulipTestCase):
self.assertIsNotNone(re.match(data['pattern'], 'ZUL2-15')) self.assertIsNotNone(re.match(data['pattern'], 'ZUL2-15'))
data['pattern'] = r'_code=(?P<id>[0-9a-zA-Z]+)' data['pattern'] = r'_code=(?P<id>[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) result = self.client_post("/json/realm/filters", info=data)
self.assert_json_success(result) self.assert_json_success(result)
self.assertIsNotNone(re.match(data['pattern'], '_code=123abcdZ')) self.assertIsNotNone(re.match(data['pattern'], '_code=123abcdZ'))
data['pattern'] = r'PR (?P<id>[0-9]+)' data['pattern'] = r'PR (?P<id>[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) result = self.client_post("/json/realm/filters", info=data)
self.assert_json_success(result) self.assert_json_success(result)
self.assertIsNotNone(re.match(data['pattern'], 'PR 123')) self.assertIsNotNone(re.match(data['pattern'], 'PR 123'))
data['pattern'] = r'lp/(?P<id>[0-9]+)' data['pattern'] = r'lp/(?P<id>[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) result = self.client_post("/json/realm/filters", info=data)
self.assert_json_success(result) self.assert_json_success(result)
self.assertIsNotNone(re.match(data['pattern'], 'lp/123')) self.assertIsNotNone(re.match(data['pattern'], 'lp/123'))
data['pattern'] = r'lp:(?P<id>[0-9]+)' data['pattern'] = r'lp:(?P<id>[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) result = self.client_post("/json/realm/filters", info=data)
self.assert_json_success(result) self.assert_json_success(result)
self.assertIsNotNone(re.match(data['pattern'], 'lp:123')) self.assertIsNotNone(re.match(data['pattern'], 'lp:123'))