From ace8fdfc30479044529a894a42177629ee059f12 Mon Sep 17 00:00:00 2001 From: LukeWH Date: Wed, 22 Nov 2023 11:30:44 +0000 Subject: [PATCH] Fix srcset lookup --- canonicalwebteam/discourse/parsers/base_parser.py | 2 +- setup.py | 2 +- tests/test_parser.py | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/canonicalwebteam/discourse/parsers/base_parser.py b/canonicalwebteam/discourse/parsers/base_parser.py index 1941b85..ce76ff1 100644 --- a/canonicalwebteam/discourse/parsers/base_parser.py +++ b/canonicalwebteam/discourse/parsers/base_parser.py @@ -613,7 +613,7 @@ def _replace_image_src(self, soup): src = img.get("src", "") if src and src.startswith("/"): img["src"] = f"{self.api.base_url}{src}" - if img["srcset"]: + if img.get("srcset", None): del img["srcset"] return soup diff --git a/setup.py b/setup.py index 8a44e15..0d564a1 100755 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ setup( name="canonicalwebteam.discourse", - version="5.4.6", + version="5.4.7", author="Canonical webteam", author_email="webteam@canonical.com", url="https://github.com/canonical/canonicalwebteam.discourse", diff --git a/tests/test_parser.py b/tests/test_parser.py index de9605b..cb702f2 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -129,6 +129,9 @@ def test_parser_upload(self): "" "" "" + "" + "" + "" "No Link" "" ), @@ -147,6 +150,14 @@ def test_parser_upload(self): ), parsed_topic["body_html"], ) + self.assertIn( + ( + '' + '' + "" + ), + parsed_topic["body_html"], + ) def test_emdash_in_slug(self): discourse_api = DiscourseAPI("https://base.url", session=MagicMock())