diff --git a/plugins/opds.koplugin/opdsparser.lua b/plugins/opds.koplugin/opdsparser.lua
index e84ca1cc3..732190cc2 100644
--- a/plugins/opds.koplugin/opdsparser.lua
+++ b/plugins/opds.koplugin/opdsparser.lua
@@ -95,6 +95,10 @@ function OPDSParser:parse(text)
-- because it doesn't really deal well with various XHTML quirks, as the list of crappy replacements above attests to...
-- There's also a high probability of finding orphaned tags or badly nested ones in there, which would screw everything up.
-- In any case, we just want to treat the whole thing as a single text node anyway, so, just mangle the markup to force luxl's hand.
+ -- A self-closing content tag (e.g. ) has no text. Turn it
+ -- into an empty element first, otherwise the lazy ".-" in the rewrite below runs
+ -- past it to the next entry's content tag and swallows everything in between.
+ text = text:gsub("]-/>", "")
text = text:gsub('', "")
text = text:gsub("(.-)", function (s)
return '' .. s:gsub("%p", {["<"] = "<", [">"] = ">", ['"'] = """, ["'"] = "'"}) .. ""
diff --git a/spec/unit/opds_spec.lua b/spec/unit/opds_spec.lua
index a3fb36b4c..0bdea704e 100644
--- a/spec/unit/opds_spec.lua
+++ b/spec/unit/opds_spec.lua
@@ -398,6 +398,39 @@ describe("OPDS module", function()
assert.are.same(entry.link[1].href, "https://www.gutenberg.org/ebooks/42474.epub.images")
assert.are.same(entry.link[1].title, "EPUB (with images)")
end)
+ it("should not desync entries when a content tag is self-closing", function()
+ -- Regression for #15511: a self-closing used to make
+ -- the content rewrite over-match into the next entry, dropping entries and
+ -- pairing covers with the wrong titles.
+ local self_closing_content_sample = [[
+
+
+Self-closing content
+
+First
+urn:first
+
+
+
+
+Second
+urn:second
+A description.
+
+
+
+]]
+ local catalog = OPDSParser:parse(self_closing_content_sample)
+ local feed = catalog.feed
+ assert.truthy(feed)
+ local entries = feed.entry
+ assert.truthy(entries)
+ assert.are.same(#entries, 2)
+ assert.are.same(entries[1].title, "First")
+ assert.are.same(entries[1].link[1].href, "FIRST_IMG")
+ assert.are.same(entries[2].title, "Second")
+ assert.are.same(entries[2].link[1].href, "SECOND_IMG")
+ end)
end)
describe("OPDS browser module", function()