Skip to content

Commit

Permalink
Handle backgrounds lacking an extension
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Aug 6, 2022
1 parent 2630f6b commit e48df4e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/models/template.py
Expand Up @@ -206,7 +206,8 @@ def build_custom_url(
text_lines[index] = text.normalize(text_lines[index])
if not extension and background:
url = furl(background)
extension = url.path.segments[-1].split(".")[-1]
if url.path.segments:
extension = url.path.segments[-1].split(".")[-1]
if extension not in settings.ALLOWED_EXTENSIONS:
extension = self._extension
if style == "default":
Expand Down
7 changes: 3 additions & 4 deletions app/tests/test_views_images.py
Expand Up @@ -427,16 +427,15 @@ def describe_POST():
@pytest.mark.parametrize("as_json", [True, False])
def it_supports_custom_backgrounds(expect, client, as_json):
data = {
"background": "https://www.gstatic.com/webp/gallery/3.png",
"background": "http://example.com",
"text_lines[]": ["foo", "bar"],
"extension": "jpg",
}
kwargs: dict = {"content": json.dumps(data)} if as_json else {"data": data}
request, response = client.post("/images/custom", **kwargs)
expect(response.status) == 201
expect(response.json) == {
"url": "http://localhost:5000/images/custom/foo/bar.jpg"
"?background=https://www.gstatic.com/webp/gallery/3.png"
"url": "http://localhost:5000/images/custom/foo/bar.png"
"?background=http://example.com"
}

def it_returns_gif_when_background_is_gif(expect, client):
Expand Down

0 comments on commit e48df4e

Please sign in to comment.