diff --git a/lib/plugins/static.js b/lib/plugins/static.js index 27ce8d78..f9dcbae7 100644 --- a/lib/plugins/static.js +++ b/lib/plugins/static.js @@ -202,13 +202,9 @@ function serveStatic(options) { } else if (opts.appendRequestPath) { file = path.join(docRoot, decodeURIComponent(req.path())); } else { - var dirBasename = path.basename(docRoot); var reqpathBasename = decodeURIComponent(path.basename(req.path())); - if ( - path.extname(reqpathBasename) === '' && - dirBasename === reqpathBasename - ) { + if (!path.extname(reqpathBasename)) { file = docRoot; } else { file = path.join(docRoot, reqpathBasename); diff --git a/test/plugins/static.test.js b/test/plugins/static.test.js index 5907850f..4b6501e9 100644 --- a/test/plugins/static.test.js +++ b/test/plugins/static.test.js @@ -476,6 +476,31 @@ describe('static resource plugin', function() { ); }); + // directory differs from path without appendPath + it('GH-1604 handling should not depend on directory name', function(done) { + var tmpDir = '.tmp'; + + function cb() { + CLIENT.get('/public/', function(err, req, res, obj) { + assert.ifError(err); + assert.equal(res.statusCode, 200); + done(); + }); + } + + serveStaticTest( + cb, + true, + tmpDir, + tmpDir + '/test', + '/test', + null, + null, + false, + null + ); + }); + // To ensure this will always get properly restored (even in case of a test // failure) we do it here. var originalCreateReadStream = fs.createReadStream;