Merge pull request #2543 from thelounge/xpaw/link-title

Fix multiple <title> tags being concatenated
This commit is contained in:
Jérémie Astori 2018-06-11 09:15:37 -04:00 committed by GitHub
commit 32ccfd50af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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();
});
});