prevent crash on non-string default values (#914)

This commit is contained in:
Jeff Williams 2015-02-08 12:54:49 -08:00
parent f92245794b
commit ea1932e4fc
2 changed files with 13 additions and 0 deletions

View File

@ -233,6 +233,10 @@ function getId(longname, id) {
var getUniqueId = exports.getUniqueId = makeUniqueId; var getUniqueId = exports.getUniqueId = makeUniqueId;
var htmlsafe = exports.htmlsafe = function(str) { var htmlsafe = exports.htmlsafe = function(str) {
if (typeof str !== 'string') {
str = String(str);
}
return str.replace(/&/g, '&') return str.replace(/&/g, '&')
.replace(/</g, '&lt;'); .replace(/</g, '&lt;');
}; };

View File

@ -473,6 +473,15 @@ describe("jsdoc/util/templateHelper", function() {
var input = '<h1>Foo & Friends</h1>'; var input = '<h1>Foo & Friends</h1>';
expect( helper.htmlsafe(input) ).toBe('&lt;h1>Foo &amp; Friends&lt;/h1>'); expect( helper.htmlsafe(input) ).toBe('&lt;h1>Foo &amp; Friends&lt;/h1>');
}); });
it('should convert non-strings to strings', function() {
function htmlsafe() {
return helper.htmlsafe(false);
}
expect(htmlsafe).not.toThrow();
expect(htmlsafe()).toBe('false');
});
}); });
describe("find", function() { describe("find", function() {