fix crash when the author tag is empty (#1289)

This commit is contained in:
Jeff Williams 2017-07-06 20:56:57 -07:00
parent 43a117d6a1
commit f1017988ec
2 changed files with 19 additions and 7 deletions

View File

@ -567,8 +567,11 @@ exports.resolveLinks = function(str) {
/** Convert tag text like "Jane Doe <jdoe@example.org>" 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 (str) {
matches = str.match(/^\s?([\s\S]+)\b\s+<(\S+@\S+)>\s?$/);
if (matches && matches.length === 3) {
author = '<a href="mailto:' + matches[2] + '">' + htmlsafe(matches[1]) + '</a>';
@ -576,6 +579,7 @@ exports.resolveAuthorLinks = function(str) {
else {
author = htmlsafe(str);
}
}
return author;
};

View File

@ -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 <jdoe@example.org> to a mailto link.
it('should convert email addresses in angle brackets *after* a name to mailto links', function() {
var str = ' John Doe <asdf.fdsa-2@gmail.com> ';