[Solved] Af_zz_imgproxy sometimes adds <a> tags in the body

When using af_zz_imgproxy, the article preview sometimes gets blank <a> tags around paragraphs, from the beginning of the article until the first actual <a> tag, resulting in part of the article being displayed like a link.

I saw it happen with one feed only, Ars Technica - All content
I don’t recall that I have seen the issue with another feed, but the feed is ok according to “myfeedsucks”. My assumption would be that this is related to the particular arrangement that Ars Technica uses to begin most of their articles (figure, image, caption, anchor, body).
It seems to happen only the first time the article is previewed. After reloading Tiny Tiny RSS, the issue disappears for an article that exhibited it. (It persists through the session though.)

tt-rss version: 1:17.4.r42.g07d3431e-1
Platform: Arch Linux, PostgreSQL 9.6.3, Nginx 1.12.1, PHP 7.1.9

Original HTML:

<div id="rss-wrap">
<figure class="intro-image intro-left"><img src="https://cdn.arstechnica.net/wp-content/uploads/2017/09/Hurricane_Harvey_from_the_ISS-800x532.jpg"><p class="caption" style="font-size:0.8em"><a href="https://cdn.arstechnica.net/wp-content/uploads/2017/09/Hurricane_Harvey_from_the_ISS.jpg" class="enlarge-link" data-height="1363" data-width="2048">Enlarge</a> <span class="sep">/</span> Harvey as seen from the International Space Station. (credit: <a rel="nofollow" class="caption-link" href="https://www.nasa.gov/feature/goddard/2017/harvey-atlantic-ocean">NASA</a>)</p>  </figure><div><a name="page-1"></a></div>
<p>Strong and sturdy as bedrock may seem, it’s possible to pile enough weight onto the Earth’s surface to squish it downward a bit. The planet’s great ice sheets, for example, have done this on a pretty significant scale. Many regions that are now relieved of the ice sheets they hosted during the last ice age are, in fact, still slowly rebounding upward today.</p>
<p>The coverage of modern, sensitive GPS networks allows us to see <a href="https://arstechnica.com/science/2014/05/groundwater-depletion-leading-to-more-earthquakes-along-san-andreas-fault/">subtler versions</a> of this process playing out even over the annual cycle of wet and dry seasons. And these networks may have caught <a href="https://arstechnica.com/science/2017/08/this-is-probably-the-worst-us-flood-storm-ever-and-ill-never-be-the-same/">Hurricane Harvey</a>’s record-setting rainfall depressing Earth’s crust just a little.</p>
<p>On Monday, Jet Propulsion Laboratory researcher Chris Milliner posted a plot of the change in GPS station elevation immediately after Harvey. The data showed that the Houston landscape had sunk as much as two centimeters. While that’s not enough to worsen flooding that was measured in (many) feet, it’s actually quite impressive for a sudden change from a single weather event. That’s a testament to the weight of the preposterous amount of water the area was under.</p>
</div>

Using af_zz_imgproxy, preview broken: (the <p>'s line 3 and 4 have additional <a>'s)

<div>
<figure><img src="https://cdn.arstechnica.net/wp-content/uploads/2017/09/Hurricane_Harvey_from_the_ISS-800x532.jpg"><p><a href="https://cdn.arstechnica.net/wp-content/uploads/2017/09/Hurricane_Harvey_from_the_ISS.jpg" data-height="1363" data-width="2048" rel="noopener noreferrer" target="_blank">Enlarge</a> <span>/</span> Harvey as seen from the International Space Station. (credit: <a rel="noopener noreferrer" href="https://www.nasa.gov/feature/goddard/2017/harvey-atlantic-ocean" target="_blank">NASA</a>)</p>  </figure><div><a name="page-1"></a></div>
<a name="page-1"><p>Strong and sturdy as bedrock may seem, it’s possible to pile enough weight onto the Earth’s surface to squish it downward a bit. The planet’s great ice sheets, for example, have done this on a pretty significant scale. Many regions that are now relieved of the ice sheets they hosted during the last ice age are, in fact, still slowly rebounding upward today.</p></a>
<p><a name="page-1">The coverage of modern, sensitive GPS networks allows us to see </a><a href="https://arstechnica.com/science/2014/05/groundwater-depletion-leading-to-more-earthquakes-along-san-andreas-fault/" rel="noopener noreferrer" target="_blank">subtler versions</a> of this process playing out even over the annual cycle of wet and dry seasons. And these networks may have caught <a href="https://arstechnica.com/science/2017/08/this-is-probably-the-worst-us-flood-storm-ever-and-ill-never-be-the-same/" rel="noopener noreferrer" target="_blank">Hurricane Harvey</a>’s record-setting rainfall depressing Earth’s crust just a little.</p>
<p>On Monday, Jet Propulsion Laboratory researcher Chris Milliner posted a plot of the change in GPS station elevation immediately after Harvey. The data showed that the Houston landscape had sunk as much as two&nbsp;centimeters. While that’s not enough to worsen flooding that was measured in (many) feet, it’s actually quite impressive for a sudden change from a single weather event. That’s a testament to the weight of the preposterous amount of water the area was under.</p>
</div>

Using af_zz_imgproxy, preview ok (after reloading):

<div>
<figure><img src="https://cdn.arstechnica.net/wp-content/uploads/2017/09/Hurricane_Harvey_from_the_ISS-800x532.jpg"><p><a href="https://cdn.arstechnica.net/wp-content/uploads/2017/09/Hurricane_Harvey_from_the_ISS.jpg" data-height="1363" data-width="2048" rel="noopener noreferrer" target="_blank">Enlarge</a> <span>/</span> Harvey as seen from the International Space Station. (credit: <a rel="noopener noreferrer" href="https://www.nasa.gov/feature/goddard/2017/harvey-atlantic-ocean" target="_blank">NASA</a>)</p>  </figure><div><a name="page-1"></a></div>
<p>Strong and sturdy as bedrock may seem, it’s possible to pile enough weight onto the Earth’s surface to squish it downward a bit. The planet’s great ice sheets, for example, have done this on a pretty significant scale. Many regions that are now relieved of the ice sheets they hosted during the last ice age are, in fact, still slowly rebounding upward today.</p>
<p>The coverage of modern, sensitive GPS networks allows us to see <a href="https://arstechnica.com/science/2014/05/groundwater-depletion-leading-to-more-earthquakes-along-san-andreas-fault/" rel="noopener noreferrer" target="_blank">subtler versions</a> of this process playing out even over the annual cycle of wet and dry seasons. And these networks may have caught <a href="https://arstechnica.com/science/2017/08/this-is-probably-the-worst-us-flood-storm-ever-and-ill-never-be-the-same/" rel="noopener noreferrer" target="_blank">Hurricane Harvey</a>’s record-setting rainfall depressing Earth’s crust just a little.</p>
<p>On Monday, Jet Propulsion Laboratory researcher Chris Milliner posted a plot of the change in GPS station elevation immediately after Harvey. The data showed that the Houston landscape had sunk as much as two&nbsp;centimeters. While that’s not enough to worsen flooding that was measured in (many) feet, it’s actually quite impressive for a sudden change from a single weather event. That’s a testament to the weight of the preposterous amount of water the area was under.</p>
</div>

Without af_zz_imgproxy:

<div>
<figure><img src="https://cdn.arstechnica.net/wp-content/uploads/2017/09/Hurricane_Harvey_from_the_ISS-800x532.jpg"><p><a href="https://cdn.arstechnica.net/wp-content/uploads/2017/09/Hurricane_Harvey_from_the_ISS.jpg" data-height="1363" data-width="2048" rel="noopener noreferrer" target="_blank">Enlarge</a> <span>/</span> Harvey as seen from the International Space Station. (credit: <a rel="noopener noreferrer" href="https://www.nasa.gov/feature/goddard/2017/harvey-atlantic-ocean" target="_blank">NASA</a>)</p>  </figure><div><a name="page-1"></a></div>
<p>Strong and sturdy as bedrock may seem, it’s possible to pile enough weight onto the Earth’s surface to squish it downward a bit. The planet’s great ice sheets, for example, have done this on a pretty significant scale. Many regions that are now relieved of the ice sheets they hosted during the last ice age are, in fact, still slowly rebounding upward today.</p>
<p>The coverage of modern, sensitive GPS networks allows us to see <a href="https://arstechnica.com/science/2014/05/groundwater-depletion-leading-to-more-earthquakes-along-san-andreas-fault/" rel="noopener noreferrer" target="_blank">subtler versions</a> of this process playing out even over the annual cycle of wet and dry seasons. And these networks may have caught <a href="https://arstechnica.com/science/2017/08/this-is-probably-the-worst-us-flood-storm-ever-and-ill-never-be-the-same/" rel="noopener noreferrer" target="_blank">Hurricane Harvey</a>’s record-setting rainfall depressing Earth’s crust just a little.</p>
<p>On Monday, Jet Propulsion Laboratory researcher Chris Milliner posted a plot of the change in GPS station elevation immediately after Harvey. The data showed that the Houston landscape had sunk as much as two&nbsp;centimeters. While that’s not enough to worsen flooding that was measured in (many) feet, it’s actually quite impressive for a sudden change from a single weather event. That’s a testament to the weight of the preposterous amount of water the area was under.</p>
</div>

I’ve noticed this too.

I think this might be due to the plugin using DOMDocument’s “saveXML” instead of “saveHTML”, resulting in an invalid self-closing anchor tag (primarily the one with name=“page-1”).

Here’s a diff if anyone wants to test it out (for new articles):

diff --git a/plugins/af_zz_imgproxy/init.php b/plugins/af_zz_imgproxy/init.php
index c3b3f7f..41fec4a 100644
--- a/plugins/af_zz_imgproxy/init.php
+++ b/plugins/af_zz_imgproxy/init.php
@@ -199,7 +199,7 @@ class Af_Zz_ImgProxy extends Plugin {
                        }
                }

-               if ($need_saving) $article["content"] = $doc->saveXML();
+               if ($need_saving) $article["content"] = $doc->saveHTML();

                return $article;
        }
@@ -257,4 +257,4 @@ class Af_Zz_ImgProxy extends Plugin {
        function api_version() {
                return 2;
        }
-}
\ No newline at end of file
+}

I confirm wn_name’s change solves the problem in the instance I was describing.

can you file a PR for this?

wn did, not sure how I can put a link to the pull request, here is my try:
https://git.tt-rss.org/git/tt-rss/pulls/6

guess i missed it, thanks