diff --git a/lib/jsdoc/name.js b/lib/jsdoc/name.js index 9de1b3d8..a759bfa2 100644 --- a/lib/jsdoc/name.js +++ b/lib/jsdoc/name.js @@ -74,7 +74,7 @@ var REGEXP_LEADING_SCOPE = new RegExp('^(' + REGEXP_SCOPE_PUNC + ')'); var REGEXP_TRAILING_SCOPE = new RegExp('(' + REGEXP_SCOPE_PUNC + ')$'); function nameIsLongname(name, memberof) { - var regexp = new RegExp('^' + memberof + REGEXP_SCOPE_PUNC); + var regexp = new RegExp('^' + escape(memberof) + REGEXP_SCOPE_PUNC); return regexp.test(name); } diff --git a/test/fixtures/objectlit3.js b/test/fixtures/objectlit3.js new file mode 100644 index 00000000..10fb33ec --- /dev/null +++ b/test/fixtures/objectlit3.js @@ -0,0 +1,10 @@ +/** Tokens that can appear in the stream. */ +var tokens = { + /** Open parenthesis. */ + '(': { + /** Executed before the token is processed. */ + before: function(token) {}, + /** Executed after the token is processed. */ + after: function(token) {} + } +}; diff --git a/test/specs/documentation/objectlit.js b/test/specs/documentation/objectlit.js index 493ca611..39bca2f1 100644 --- a/test/specs/documentation/objectlit.js +++ b/test/specs/documentation/objectlit.js @@ -42,4 +42,26 @@ describe('object literals', function() { expect(found[0].scope).toBe('static'); }); }); + + describe('When an object literal\'s property names must be escaped in a regexp', function() { + var docSet; + var found; + + function loadDocSet() { + docSet = jasmine.getDocSetFromFile('test/fixtures/objectlit3.js'); + found = docSet.getByLongname('tokens.(.before'); + } + + it('should not throw an error when creating a doclet', function() { + expect(loadDocSet).not.toThrow(); + }); + + it('should have a doclet with the correct name', function() { + expect(found[0].name).toBe('before'); + }); + + it('should have a doclet with the correct memberof', function() { + expect(found[0].memberof).toBe('tokens.('); + }); + }); });