Skip to content

Commit

Permalink
fix crash when the author tag is empty (#1289)
Browse files Browse the repository at this point in the history
  • Loading branch information
hegemonic committed Jul 7, 2017
1 parent 43a117d commit f101798
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/jsdoc/util/templateHelper.js
Expand Up @@ -567,14 +567,18 @@ 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 (matches && matches.length === 3) {
author = '<a href="mailto:' + matches[2] + '">' + htmlsafe(matches[1]) + '</a>';
}
else {
author = htmlsafe(str);
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>';
}
else {
author = htmlsafe(str);
}
}

return author;
Expand Down
8 changes: 8 additions & 0 deletions test/specs/jsdoc/util/templateHelper.js
Expand Up @@ -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> ';
Expand Down

0 comments on commit f101798

Please sign in to comment.