Skip to content

Commit

Permalink
Default to the "original" SVG rendition if none of the passed filters…
Browse files Browse the repository at this point in the history
… SVG-safe
  • Loading branch information
zerolab committed Apr 21, 2024
1 parent bb94111 commit 41b4950
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions grapple/types/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ def resolve_rendition(
if instance.is_svg() and preserve_svg:
# when dealing with SVGs, we want to limit the filter specs to those that are safe
filter_specs = to_svg_safe_spec(filter_specs)
if not filter_specs:
# if there are no valid filters, fall back to the original
filter_specs = "original"

if not filter_specs:
raise TypeError(
Expand Down
16 changes: 10 additions & 6 deletions tests/test_image_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ def test_svg_rendition_with_raster_format_with_preserve_svg(self):
query, variables={"id": self.example_svg_image.id}
)
self.assertTrue(
results["data"]["image"]["rendition"]["url"].endswith("test.width-150.svg")
results["data"]["image"]["rendition"]["url"].endswith(
"grapple-test.width-150.svg"
)
)

def test_svg_src_set_with_raster_format_with_preserve_svg(self):
Expand All @@ -318,7 +320,9 @@ def test_svg_src_set_with_raster_format_with_preserve_svg(self):
query, variables={"id": self.example_svg_image.id}
)
self.assertTrue(
results["data"]["image"]["srcSet"].split()[0].endswith("test.width-100.svg")
results["data"]["image"]["srcSet"]
.split()[0]
.endswith("grapple-test.width-100.svg")
)

def test_svg_rendition_with_raster_format_without_preserve_svg(self):
Expand Down Expand Up @@ -372,8 +376,8 @@ def test_svg_rendition_with_filters_passed_through_to_svg_safe_spec(self):
results = self.client.execute(
query, variables={"id": self.example_svg_image.id}
)
self.assertIsNone(results["data"]["image"]["rendition"])
self.assertEqual(
results["errors"][0]["message"],
"No valid filter specs for SVG. See https://docs.wagtail.org/en/stable/topics/images.html#svg-images for details.",
self.assertTrue(
results["data"]["image"]["rendition"]["url"].endswith(
"grapple-test.original.svg"
)
)

0 comments on commit 41b4950

Please sign in to comment.