Ticket #12285 (confirmed Bug)
plone.outputfilters and img without src attribute
Reported by: | naro | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | 4.x |
Component: | General | Version: | 4.1 |
Keywords: | Cc: |
Description
I've got Plone Document with this tag: <img class="image-left captioned" /> I don't know how it was created, it is migrated site. The problem is, plone.outputfilters incorrectly replaces src attribute with current context URL and p.a.imaging fails on parsing src="/path/to/document" image scale.
What would be correct behavior of plone.outputfilters? Leave invalid img tag as is or remove it from output document ?
Added test and test failure:
diff --git a/plone/outputfilters/tests/test_resolveuid_and_caption.py b/plone/outputfilters/tests/test_resolveuid_and_caption.py index d2b5680..fedd259 100644 --- a/plone/outputfilters/tests/test_resolveuid_and_caption.py +++ b/plone/outputfilters/tests/test_resolveuid_and_caption.py @@ -277,6 +277,11 @@ alert(1); text_in = """<img class="captioned" src="image.jpg"/>""" self._assertTransformsTo(text_in, 'foo') + def test_image_without_src_attribute(self): + # Drop any img tags without 'src' attribute. This would break p.a.imaging + text_in = """<img class="image-left" />""" + text_out = "" + self._assertTransformsTo(text_in, text_out) def test_suite(): return unittest.defaultTestLoader.loadTestsFromName(__name__) Test failure: + <img src="http://nohost/plone" alt="Plone site" class="image-left" title="Plone site" />
First solution (leave invalid tag as is):
diff --git a/plone/outputfilters/filters/resolveuid_and_caption.py b/plone/outputfilters/filters/resolveuid_and_caption.py index 9133455..626c610 100644 --- a/plone/outputfilters/filters/resolveuid_and_caption.py +++ b/plone/outputfilters/filters/resolveuid_and_caption.py @@ -151,6 +151,8 @@ class ResolveUIDAndCaptionFilter(SGMLParser): return obj, subpath, appendix def resolve_image(self, src): + if not src: + return None, None, src, '' description = '' if urlsplit(src)[0]: # We have a scheme diff --git a/plone/outputfilters/tests/test_resolveuid_and_caption.py b/plone/outputfilters/tests/test_resolveuid_and_caption.py index d2b5680..061eabe 100644 --- a/plone/outputfilters/tests/test_resolveuid_and_caption.py +++ b/plone/outputfilters/tests/test_resolveuid_and_caption.py @@ -277,6 +277,11 @@ alert(1); text_in = """<img class="captioned" src="image.jpg"/>""" self._assertTransformsTo(text_in, 'foo') + def test_image_without_src_attribute(self): + # Drop any img tags without 'src' attribute. This would break p.a.imaging + text_in = """<img class="image-left" />""" + text_out = """<img class="image-left" />""" + self._assertTransformsTo(text_in, text_out) def test_suite(): return unittest.defaultTestLoader.loadTestsFromName(__name__)
Second solution (remove it):
diff --git a/plone/outputfilters/filters/resolveuid_and_caption.py b/plone/outputfilters/filters/resolveuid_and_caption.py index 9133455..0f33090 100644 --- a/plone/outputfilters/filters/resolveuid_and_caption.py +++ b/plone/outputfilters/filters/resolveuid_and_caption.py @@ -295,6 +295,8 @@ class ResolveUIDAndCaptionFilter(SGMLParser): attrs = attributes.iteritems() elif tag == 'img': src = attributes.get('src', '') + if not src: + return False image, fullimage, src, description = self.resolve_image(src) attributes["src"] = src caption = description diff --git a/plone/outputfilters/tests/test_resolveuid_and_caption.py b/plone/outputfilters/tests/test_resolveuid_and_caption.py index d2b5680..ffddc8e 100644 --- a/plone/outputfilters/tests/test_resolveuid_and_caption.py +++ b/plone/outputfilters/tests/test_resolveuid_and_caption.py @@ -277,6 +277,11 @@ alert(1); text_in = """<img class="captioned" src="image.jpg"/>""" self._assertTransformsTo(text_in, 'foo') + def test_image_without_src_attribute(self): + # Drop any img tags without 'src' attribute. This would break p.a.imaging + text_in = """<p><img class="image-left" /></p>""" + text_out = "<p></p>" + self._assertTransformsTo(text_in, text_out) def test_suite(): return unittest.defaultTestLoader.loadTestsFromName(__name__)
Change History
Note: See
TracTickets for help on using
tickets.
Which Plone version please?