Skip to content

Commit 3d1d99c

Browse files
committed
Fix rendering of unquoted empty attributes.
1 parent 98bfeb4 commit 3d1d99c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ function render (tree, options) {
8282
if (typeof obj[key] === 'string') {
8383
if (quoteAllAttributes || obj[key].match(ATTRIBUTE_QUOTES_REQUIRED)) {
8484
attr += ' ' + key + '="' + obj[key].replace(/"/g, '"') + '"'
85+
} else if (obj[key] === '') {
86+
attr += ' ' + key
8587
} else {
8688
attr += ' ' + key + '=' + obj[key]
8789
}

test/render.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,15 @@ describe('PostHTML Render', function () {
327327
expect(render(fixture, options)).to.eql(expected)
328328
})
329329

330+
it('Required Empty', function () {
331+
var options = { quoteAllAttributes: false }
332+
333+
var fixture = { tag: 'script', attrs: { async: '' } }
334+
var expected = '<script async></script>'
335+
336+
expect(render(fixture, options)).to.eql(expected)
337+
})
338+
330339
it('Closing slash', function () {
331340
var options = {
332341
closingSingleTag: 'slash',

0 commit comments

Comments
 (0)