Skip to content

Commit

Permalink
Ensure null/undefined id is not rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebayes committed Oct 14, 2024
1 parent ea10101 commit bf394e9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nomplate",
"version": "1.3.27",
"version": "1.3.28",
"description": "Nomplate: Node template engine",
"main": "index.js",
"engines": {
Expand Down
4 changes: 3 additions & 1 deletion src/operations.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ function top(stack) {

function setId(value) {
return function _setId(domElement, stack, document) {
domElement.id = value;
if (value !== null && value !== undefined) {
domElement.id = value;
}
return domElement;
};
}
Expand Down
5 changes: 5 additions & 0 deletions test/render_element_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ describe('renderElement', () => {
assert.equal(domElement.outerHTML, '<div id="abcd"></div>');
});

it('creates element with null id', () => {
const domElement = renderElement(dom.div({id: null}), doc);
assert.equal(domElement.outerHTML, '<div></div>');
});

it('assigns textContent', () => {
const domElement = renderElement(dom.div('one'), doc);
assert.equal(domElement.outerHTML, '<div>one</div>');
Expand Down

0 comments on commit bf394e9

Please sign in to comment.