Skip to content

Commit

Permalink
fix(tocObj): return empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Feb 23, 2020
1 parent 6b18598 commit 6f796aa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/toc_obj.js
Expand Up @@ -10,7 +10,7 @@ const parseHtml = html => {
};

const getId = ({ attribs, parent }) => {
return attribs.id || (!parent ? null : getId(parent));
return attribs.id || (!parent ? '' : getId(parent));
};

function tocObj(str, options = {}) {
Expand Down
8 changes: 2 additions & 6 deletions test/toc_obj.spec.js
Expand Up @@ -66,19 +66,15 @@ describe('tocObj', () => {
it('no id attribute', () => {
const noid = '<h1>Title 1</h1>';
const result = tocObj(noid);
const checkNull = result[0].id === null;

result.length.should.eql(1);
checkNull.should.eql(true);
result[0].id.should.eql('');
});

it('empty value in id attribute', () => {
const noid = '<h1 id="">Title 1</h1>';
const result = tocObj(noid);
const checkNull = result[0].id === null;

result.length.should.eql(1);
checkNull.should.eql(true);
result[0].id.should.eql('');
});

it('invalid input', () => {
Expand Down

0 comments on commit 6f796aa

Please sign in to comment.