Skip to content

Commit

Permalink
Allow dots in value of public option (#29)
Browse files Browse the repository at this point in the history
* test relativePath for extension, allowing paths with dots in the for the "public" setting

* Added regression test

* Correctly check for env

* Fixed tests
  • Loading branch information
andyburke authored and leo committed Jun 15, 2018
1 parent b1679e5 commit aca05e8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ const renderDirectory = async (current, acceptsJSON, handlers, methods, config,
const sendError = async (response, acceptsJSON, current, handlers, config, spec) => {
const {err: original, message, code, statusCode} = spec;

if (original) {
/* istanbul ignore next */
if (original && process.env.NODE_ENV !== 'test') {
console.error(original);
}

Expand Down Expand Up @@ -534,7 +535,7 @@ module.exports = async (request, response, config = {}, methods = {}) => {
// one of them includes the path of the directory. As that's a very
// performance-expensive thing to do, we need to ensure it's not happening if not really necessary.

if (path.extname(absolutePath) !== '') {
if (path.extname(relativePath) !== '') {
try {
stats = await handlers.stat(absolutePath);
} catch (err) {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/public-folder.test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<span>I am a test for a directory with a dot in the name</span>
30 changes: 27 additions & 3 deletions test/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -754,16 +754,23 @@ test('error occurs while getting stat of path', async t => {

// eslint-disable-next-line no-undefined
const url = await getUrl(undefined, {
stat: () => {
throw new Error(message);
stat: location => {
if (path.basename(location) !== '500.html') {
throw new Error(message);
}
}
});

const response = await fetch(url);
const text = await response.text();

const content = errorTemplate({
statusCode: 500,
message: 'A server error has occurred'
});

t.is(response.status, 500);
t.is(text, message);
t.is(text, content);
});

test('the first `stat` call should be for a related file', async t => {
Expand Down Expand Up @@ -932,3 +939,20 @@ test('correctly handle requests to /index if `cleanUrls` is enabled', async t =>
t.is(location, `${url}/`);
});

test('allow dots in `public` configuration property', async t => {
const directory = 'public-folder.test';
const root = path.join(fixturesTarget, directory);
const file = path.join(fixturesFull, directory, 'index.html');

const url = await getUrl({
'public': root,
'directoryListing': false
});

const response = await fetch(url);
const text = await response.text();
const content = await fs.readFile(file, 'utf8');

t.is(response.status, 200);
t.is(content, text);
});

0 comments on commit aca05e8

Please sign in to comment.