Fix multiple <title> tags being concatenated

This commit is contained in:
Pavel Djundik 2018-06-11 11:32:32 +03:00
parent 12cd1b2614
commit 0d48c596c8
2 changed files with 20 additions and 2 deletions

View file

@ -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")

View file

@ -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("<title>test</title><title>magnifying glass icon</title><meta name='description' content='desc1'><meta name='description' content='desc2'>");
});
this.irc.once("msg:preview", function(data) {
expect(data.preview.head).to.equal("test");
expect(data.preview.body).to.equal("desc1");
done();
});
});