mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
stream: Fix validator for stream colors.
Apparently, our new validator for stream color having a valid format incorrectly handled colors that had duplicate characters in them. (This is caused in part by the spectrum.js logic automatically converting #ffff00 to #ff0, which our validator rejected). Given that we had old stream colors in the #ff0 format in our database anyway for legacy, there's no benefit to banning these colors. In the future, we could imagine standardizing the format, but doing so will require also changing the frontend to submit colors only in the 6-character format. Fixes an issue reported in https://github.com/zulip/zulip/issues/11845#issuecomment-471417073
This commit is contained in:
@@ -105,7 +105,7 @@ def check_bool(var_name: str, val: object) -> Optional[str]:
|
|||||||
def check_color(var_name: str, val: object) -> Optional[str]:
|
def check_color(var_name: str, val: object) -> Optional[str]:
|
||||||
if not isinstance(val, str):
|
if not isinstance(val, str):
|
||||||
return _('%s is not a string') % (var_name,)
|
return _('%s is not a string') % (var_name,)
|
||||||
valid_color_pattern = re.compile(r'^#(?:[a-fA-F0-9]{6})$')
|
valid_color_pattern = re.compile(r'^#([a-fA-F0-9]{3,6})$')
|
||||||
matched_results = valid_color_pattern.match(val)
|
matched_results = valid_color_pattern.match(val)
|
||||||
if not matched_results:
|
if not matched_results:
|
||||||
return _('%s is not a valid hex color code') % (var_name,)
|
return _('%s is not a valid hex color code') % (var_name,)
|
||||||
|
|||||||
@@ -772,7 +772,7 @@ class ValidatorTestCase(TestCase):
|
|||||||
self.assertEqual(check_float('x', x), 'x is not a float')
|
self.assertEqual(check_float('x', x), 'x is not a float')
|
||||||
|
|
||||||
def test_check_color(self) -> None:
|
def test_check_color(self) -> None:
|
||||||
x = ['#000099', '#80ffaa', '#80FFAA', '#abcd12'] # valid
|
x = ['#000099', '#80ffaa', '#80FFAA', '#abcd12', '#ffff00', '#ff0', '#f00'] # valid
|
||||||
y = ['000099', '#80f_aa', '#80fraa', '#abcd1234', 'blue'] # invalid
|
y = ['000099', '#80f_aa', '#80fraa', '#abcd1234', 'blue'] # invalid
|
||||||
z = 5 # invalid
|
z = 5 # invalid
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user