Raise ValueError if color specifier is too long

This commit is contained in:
Hugo van Kemenade 2021-08-23 19:10:49 +03:00
parent bd5cf7db87
commit 9e08eb8f78
2 changed files with 11 additions and 0 deletions

View File

@ -191,3 +191,12 @@ def test_rounding_errors():
assert (255, 255) == ImageColor.getcolor("white", "LA")
assert (163, 33) == ImageColor.getcolor("rgba(0, 255, 115, 33)", "LA")
Image.new("LA", (1, 1), "white")
def test_color_too_long():
# Arrange
color_too_long = "hsl(" + "1" * 100 + ")"
# Act / Assert
with pytest.raises(ValueError):
ImageColor.getrgb(color_too_long)

View File

@ -32,6 +32,8 @@ def getrgb(color):
:param color: A color string
:return: ``(red, green, blue[, alpha])``
"""
if len(color) > 100:
raise ValueError("color specifier is too long")
color = color.lower()
rgb = colormap.get(color, None)