Skip to content

Commit

Permalink
fix(restifyGH-1604): plugins.serveStatic no dep dirname
Browse files Browse the repository at this point in the history
Fixes restify#1604
There should be no dependency on the dirname for specific path.
  • Loading branch information
kolbma committed May 26, 2022
1 parent d7f32ea commit c85da14
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 @@ -186,13 +186,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 c85da14

Please sign in to comment.