Skip to content

Commit

Permalink
chore: ensure content is not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Oct 18, 2024
1 parent 5ef84c4 commit 4508f32
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
13 changes: 13 additions & 0 deletions test/html/rewrite-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(['<meta content="" name="twitter:description">']),
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,
Expand Down

0 comments on commit 4508f32

Please sign in to comment.