Skip to content

Commit

Permalink
Merge pull request #2 from kolbma/restifyGH-1604
Browse files Browse the repository at this point in the history
plugins.serveStatic Fixes restifyGH-1604
  • Loading branch information
kolbma authored May 26, 2022
2 parents 02c1497 + c85da14 commit 7f36ae1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/plugins/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions test/plugins/static.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7f36ae1

Please sign in to comment.