From f1017988ec4c6175b101dbde47fb06b75d205c70 Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Thu, 6 Jul 2017 20:56:57 -0700 Subject: [PATCH] fix crash when the author tag is empty (#1289) --- lib/jsdoc/util/templateHelper.js | 18 +++++++++++------- test/specs/jsdoc/util/templateHelper.js | 8 ++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/jsdoc/util/templateHelper.js b/lib/jsdoc/util/templateHelper.js index cdef6e16..b40e0ea7 100644 --- a/lib/jsdoc/util/templateHelper.js +++ b/lib/jsdoc/util/templateHelper.js @@ -567,14 +567,18 @@ exports.resolveLinks = function(str) { /** Convert tag text like "Jane Doe " into a mailto link */ exports.resolveAuthorLinks = function(str) { - var author; - var matches = str.match(/^\s?([\s\S]+)\b\s+<(\S+@\S+)>\s?$/); + var author = ''; + var matches; - if (matches && matches.length === 3) { - author = '' + htmlsafe(matches[1]) + ''; - } - else { - author = htmlsafe(str); + if (str) { + matches = str.match(/^\s?([\s\S]+)\b\s+<(\S+@\S+)>\s?$/); + + if (matches && matches.length === 3) { + author = '' + htmlsafe(matches[1]) + ''; + } + else { + author = htmlsafe(str); + } } return author; diff --git a/test/specs/jsdoc/util/templateHelper.js b/test/specs/jsdoc/util/templateHelper.js index 137fe1a5..60be0437 100644 --- a/test/specs/jsdoc/util/templateHelper.js +++ b/test/specs/jsdoc/util/templateHelper.js @@ -1840,6 +1840,14 @@ describe("jsdoc/util/templateHelper", function() { }); describe("resolveAuthorLinks", function() { + it('should not crash JSDoc if no text is specified', function() { + function resolve() { + helper.resolveAuthorLinks(); + } + + expect(resolve).not.toThrow(); + }); + // convert Jane Doe to a mailto link. it('should convert email addresses in angle brackets *after* a name to mailto links', function() { var str = ' John Doe ';