diff --git a/src/html.js b/src/html.js index fa082ba..e6e3bcb 100644 --- a/src/html.js +++ b/src/html.js @@ -93,6 +93,7 @@ const addBody = ({ url, headers, html }) => { const rewriteMetaTags = ({ $ }) => { $('meta').each((_, element) => { const el = $(element) + if (!el.attr('content')) return const name = el.attr('name') const property = el.attr('property') diff --git a/test/html/rewrite-html.js b/test/html/rewrite-html.js index d9fcea4..ef89fab 100644 --- a/test/html/rewrite-html.js +++ b/test/html/rewrite-html.js @@ -41,6 +41,19 @@ test("don't rewrite og if property is already present", async t => { ) }) +test("don't rewrite og if content is empty", async t => { + const output = html({ + rewriteHtml: true, + url: 'https://kikobeats.com', + html: composeHtml(['']), + headers: { 'content-type': 'text/html; charset=utf-8' } + }) + + const $ = cheerio.load(output) + t.is($('meta[name="twitter:description"]').attr('content'), '') + t.is($('meta[property="twitter:description"]').attr('content'), undefined) +}) + test('rewrite multiple og wrong markup', async t => { const output = html({ rewriteHtml: true,