diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-09-28 00:57:56 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-12-22 15:00:48 +0100 |
commit | 7f95f600487eead5085b9a5e2d4d878cc9648e68 (patch) | |
tree | 7bb59c38e420c8ac3f503548fdbafb61dc215e70 | |
parent | 065cf8d9c5b116ee7259f94e92c0ada7df35020b (diff) | |
download | gitbook-7f95f600487eead5085b9a5e2d4d878cc9648e68.zip gitbook-7f95f600487eead5085b9a5e2d4d878cc9648e68.tar.gz gitbook-7f95f600487eead5085b9a5e2d4d878cc9648e68.tar.bz2 |
Fix #5: Throw error when entry is invalid (no text)
-rw-r--r-- | packages/gitbook-markdown/lib/summary.js | 1 | ||||
-rw-r--r-- | packages/gitbook-markdown/test/fixtures/SUMMARY_SUBLIST.md | 6 | ||||
-rw-r--r-- | packages/gitbook-markdown/test/summary.js | 9 |
3 files changed, 16 insertions, 0 deletions
diff --git a/packages/gitbook-markdown/lib/summary.js b/packages/gitbook-markdown/lib/summary.js index 2cb31be..77284cf 100644 --- a/packages/gitbook-markdown/lib/summary.js +++ b/packages/gitbook-markdown/lib/summary.js @@ -103,6 +103,7 @@ function parseTitle(src) { function parseChapter(nodes) { var node = _.first(nodes); if (!node) return null; + if (!node.text) throw new Error("Invalid entry in the SUMMARY"); return _.extend(parseTitle(node.text), { articles: _.chain(listSplit(filterList(nodes), 'list_item_start', 'list_item_end')) diff --git a/packages/gitbook-markdown/test/fixtures/SUMMARY_SUBLIST.md b/packages/gitbook-markdown/test/fixtures/SUMMARY_SUBLIST.md new file mode 100644 index 0000000..9f21215 --- /dev/null +++ b/packages/gitbook-markdown/test/fixtures/SUMMARY_SUBLIST.md @@ -0,0 +1,6 @@ +# Summary + +* Test +* 1. Landform + + diff --git a/packages/gitbook-markdown/test/summary.js b/packages/gitbook-markdown/test/summary.js index 98cd57f..a1bb49a 100644 --- a/packages/gitbook-markdown/test/summary.js +++ b/packages/gitbook-markdown/test/summary.js @@ -56,6 +56,15 @@ describe('Summary parsing', function () { assert.equal(l.chapters.length, 1); }); + it('should throw error for sublist entries', function() { + assert.throws( + function() { + var l = lex('SUMMARY_SUBLIST.md'); + }, + "Invalid entry in the SUMMARY" + ); + }); + it('should correctly convert it to text', function() { var text = summary.toText(LEXED); assertObjectsEqual(summary(text), LEXED); |