From 8a6fe881e8a219f0784b3048dd6df5cffb8b00ce Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Thu, 2 May 2013 22:00:21 -0700 Subject: [PATCH] resolve relative paths before scanning/filtering (#405) --- lib/jsdoc/src/filter.js | 12 +++++++++++- lib/jsdoc/src/scanner.js | 10 +++++++--- test/specs/jsdoc/src/filter.js | 5 +++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/jsdoc/src/filter.js b/lib/jsdoc/src/filter.js index 091b37c8..4bd18055 100644 --- a/lib/jsdoc/src/filter.js +++ b/lib/jsdoc/src/filter.js @@ -5,6 +5,8 @@ @license Apache License 2.0 - See file 'LICENSE.md' in this project. */ +var path = require('jsdoc/path'); + /** @constructor @param {object} opts @@ -13,7 +15,13 @@ @param {string|RegExp} opts.excludePattern */ exports.Filter = function(opts) { - this.exclude = opts.exclude || null; + var cwd = process.cwd(); + + this.exclude = opts.exclude && Array.isArray(opts.exclude) ? + opts.exclude.map(function($) { + return path.resolve(cwd, $); + }) : + null; this.includePattern = opts.includePattern? typeof opts.includePattern === 'string'? new RegExp(opts.includePattern) : opts.includePattern : null; @@ -27,6 +35,8 @@ exports.Filter = function(opts) { @returns {boolean} Should the given file be included? */ exports.Filter.prototype.isIncluded = function(filepath) { + filepath = path.resolve(process.cwd(), filepath); + if ( this.includePattern && !this.includePattern.test(filepath) ) { return false; } diff --git a/lib/jsdoc/src/scanner.js b/lib/jsdoc/src/scanner.js index 4496ce27..914cf7fe 100644 --- a/lib/jsdoc/src/scanner.js +++ b/lib/jsdoc/src/scanner.js @@ -8,6 +8,7 @@ var fs = require('jsdoc/fs'); +var path = require('jsdoc/path'); /** @constructor @@ -23,7 +24,8 @@ exports.Scanner.prototype = Object.create( require('events').EventEmitter.protot @fires sourceFileFound */ exports.Scanner.prototype.scan = function(searchPaths, depth, filter) { - var filePaths = [], + var cwd = process.cwd(), + filePaths = [], self = this; searchPaths = searchPaths || []; @@ -32,10 +34,12 @@ exports.Scanner.prototype.scan = function(searchPaths, depth, filter) { searchPaths.forEach(function($) { var filepath = decodeURIComponent($); if ( fs.statSync(filepath).isFile() ) { - filePaths.push(filepath); + filePaths.push( path.resolve(cwd, filepath) ); } else { - filePaths = filePaths.concat(fs.ls(filepath, depth)); + filePaths = filePaths.concat( fs.ls(filepath, depth).map(function(item) { + return path.resolve(cwd, item); + }) ); } }); diff --git a/test/specs/jsdoc/src/filter.js b/test/specs/jsdoc/src/filter.js index 9d744271..c34d0aae 100644 --- a/test/specs/jsdoc/src/filter.js +++ b/test/specs/jsdoc/src/filter.js @@ -1,3 +1,4 @@ +/*global describe: true, expect: true, it: true */ describe("jsdoc/src/filter", function() { var filter = new (require('jsdoc/src/filter').Filter)({ includePattern: new RegExp(".+\\.js(doc)?$"), @@ -5,7 +6,7 @@ describe("jsdoc/src/filter", function() { exclude: ['.ignore', 'scratch/conf.js'] }); - var files = ['yes.js', '/yes.jsdoc', '/_nope.js', '.ignore']; + var files = ['yes.js', '/yes.jsdoc', '/_nope.js', '.ignore', process.cwd() + '/scratch/conf.js']; files = files.filter(function($) { return filter.isIncluded($); @@ -16,4 +17,4 @@ describe("jsdoc/src/filter", function() { expect(files.indexOf("yes.js")).toBeGreaterThan(-1); expect(files.indexOf("/yes.jsdoc")).toBeGreaterThan(-1); }); -}); \ No newline at end of file +});