From 768a61c630cd3817fb5565cc6a3e68b49d51102f Mon Sep 17 00:00:00 2001 From: "Christopher D. Parks" Date: Wed, 5 Nov 2014 17:25:12 -0800 Subject: [PATCH] Falling back to regex solution for default value when value is malformed Added the following tests which fail without the patch and pass with it: 1) should fail gracefully when the default value has an unmatched bracket 2) should fail gracefully when the default value has an unmatched quote --- lib/jsdoc/name.js | 6 +++++- test/specs/jsdoc/name.js | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/jsdoc/name.js b/lib/jsdoc/name.js index 41d4e0d5..f2dc3f32 100644 --- a/lib/jsdoc/name.js +++ b/lib/jsdoc/name.js @@ -408,8 +408,12 @@ exports.splitName = function(nameDesc) { // dash as a separator // optional values get special treatment + var result = null; if (nameDesc[0] === '[') { - return splitNameMatchingBrackets(nameDesc); + result = splitNameMatchingBrackets(nameDesc); + if (result !== null) { + return result; + } } nameDesc.match(REGEXP_NAME_DESCRIPTION); diff --git a/test/specs/jsdoc/name.js b/test/specs/jsdoc/name.js index 22e09ba7..e20e86d2 100644 --- a/test/specs/jsdoc/name.js +++ b/test/specs/jsdoc/name.js @@ -264,6 +264,24 @@ describe('jsdoc/name', function() { expect(parts.name).toBe('[path=["Unmatched begin: ["]]'); expect(parts.description).toBe('Path split into components'); }); + + it('should fail gracefully when the default value has an unmatched bracket', function() { + var startName = '[path=["home", "user"] - Path split into components' + var parts = jsdoc.name.splitName(startName); + + expect(parts).not.toBe(null); + expect(parts.name).toBe('[path=["home", "user"]'); + expect(parts.description).toBe('Path split into components'); + }); + + it('should fail gracefully when the default value has an unmatched quote', function() { + var startName = '[path=["home", "user] - Path split into components' + var parts = jsdoc.name.splitName(startName); + + expect(parts).not.toBe(null); + expect(parts.name).toBe('[path=["home", "user]'); + expect(parts.description).toBe('Path split into components'); + }); }); describe('resolve', function() {