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

View File

@ -1840,6 +1840,14 @@ describe("jsdoc/util/templateHelper", function() {
}); });
describe("resolveAuthorLinks", 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. // 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() { it('should convert email addresses in angle brackets *after* a name to mailto links', function() {
var str = ' John Doe <asdf.fdsa-2@gmail.com> '; var str = ' John Doe <asdf.fdsa-2@gmail.com> ';