Skip to content

Commit

Permalink
Merge pull request #3 from i-like-robots/master
Browse files Browse the repository at this point in the history
Do not close void elements
  • Loading branch information
developit committed Mar 19, 2016
2 parents 4927e5f + bd208bf commit 71afd4a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
22 changes: 21 additions & 1 deletion server/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ const ESC = {

const EMPTY = {};

const VOID_ELEMENTS = [
'area',
'base',
'br',
'col',
'embed',
'hr',
'img',
'input',
'link',
'meta',
'param',
'source',
'track',
'wbr'
];

const HOP = Object.prototype.hasOwnProperty;

let encodeEntities = s => String(s).replace(/[<>"&]/g, escapeChar);
Expand Down Expand Up @@ -127,7 +144,10 @@ export default function renderToString(vnode, context, opts, inner) {
}
}

s += `</${nodeName}>`
if (VOID_ELEMENTS.indexOf(nodeName) === -1) {
s += `</${nodeName}>`;
}

return s;
};

Expand Down
14 changes: 14 additions & 0 deletions server/test/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ describe('render', () => {

expect(rendered).to.equal(expected);
});

it('does not close void elements', () => {
let rendered, expected;

rendered = render(<div><input type='text' /><wbr /></div>);
expected = `<div><input type="text"><wbr></div>`;

expect(rendered).to.equal(expected);

rendered = render(<input><p>Hello World</p></input>);
expected = `<input><p>Hello World</p>`;

expect(rendered).to.equal(expected);
});
});

describe('Functional Components', () => {
Expand Down

0 comments on commit 71afd4a

Please sign in to comment.