diff --git a/src/plugins/irc-events/link.js b/src/plugins/irc-events/link.js index e8207a71..d32d94d5 100644 --- a/src/plugins/irc-events/link.js +++ b/src/plugins/irc-events/link.js @@ -86,7 +86,7 @@ function parseHtml(preview, res, client) { preview.type = "link"; preview.head = $('meta[property="og:title"]').attr("content") - || $("title").text() + || $("head > title, title").first().text() || ""; preview.body = $('meta[property="og:description"]').attr("content") diff --git a/test/plugins/link.js b/test/plugins/link.js index eb1ccee7..6fd5cdca 100644 --- a/test/plugins/link.js +++ b/test/plugins/link.js @@ -72,7 +72,25 @@ describe("Link plugin", function() { }); this.irc.once("msg:preview", function(data) { - expect(data.preview.head, "opengraph test"); + expect(data.preview.head).to.equal("opengraph test"); + done(); + }); + }); + + it("should find only the first matching tag", function(done) { + const message = this.irc.createMessage({ + text: "http://localhost:9002/duplicate-tags", + }); + + link(this.irc, this.network.channels[0], message); + + app.get("/duplicate-tags", function(req, res) { + res.send("testmagnifying glass icon"); + }); + + this.irc.once("msg:preview", function(data) { + expect(data.preview.head).to.equal("test"); + expect(data.preview.body).to.equal("desc1"); done(); }); });