diff --git a/lib/jsdoc/util/templateHelper.js b/lib/jsdoc/util/templateHelper.js index e52ea89c..c9417064 100644 --- a/lib/jsdoc/util/templateHelper.js +++ b/lib/jsdoc/util/templateHelper.js @@ -98,7 +98,7 @@ var longnameToUrl = exports.longnameToUrl = linkMap.longnameToUrl; var linkto = exports.linkto = function(longname, linktext, cssClass) { var classString = cssClass ? util.format(' class="%s"', cssClass) : ''; var text = linktext || longname; - var url = longnameToUrl[longname]; + var url = hasOwnProp.call(longnameToUrl, longname) && longnameToUrl[longname]; if (!url) { return text; @@ -356,7 +356,7 @@ function toLink(longname, content, monospace) { } else { // the actual longname is stored in `url` if there was a delimiter. - url = linkMap.longnameToUrl[longname]; + url = hasOwnProp.call(linkMap.longnameToUrl, longname) && linkMap.longnameToUrl[longname]; } content = content || longname; diff --git a/test/specs/jsdoc/util/templateHelper.js b/test/specs/jsdoc/util/templateHelper.js index 6718a820..f33f635e 100644 --- a/test/specs/jsdoc/util/templateHelper.js +++ b/test/specs/jsdoc/util/templateHelper.js @@ -235,6 +235,13 @@ describe("jsdoc/util/templateHelper", function() { var link = helper.linkto('linktoTest', 'link text', 'myclass'); expect(link).toEqual('link text'); }); + + it("is careful with longnames that are reserved words in JS", function() { + // we don't have a registered link for 'constructor' so it should return the text 'link text'. + var link = helper.linkto('constructor', 'link text'); + expect(typeof link).toBe('string'); + expect(link).toBe('link text'); + }); }); describe("htmlsafe", function() { @@ -952,6 +959,12 @@ describe("jsdoc/util/templateHelper", function() { expect(output).toEqual('Link to test'); }); + it('should be careful with linking to links whose names are reserved JS keywords', function() { + var input = 'Link to {@link constructor}', + output = helper.resolveLinks(input); + expect(output).toBe('Link to constructor'); + }); + // conf.monospaceLinks. check that // a) it works it('if conf.monospaceLinks is true, all {@link} should be monospace', function () {