Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #254 from akihikodaki/dot_strict
Browse files Browse the repository at this point in the history
Ignore files and directories with leading dots except .well-known
  • Loading branch information
Rich-Harris authored May 4, 2018
2 parents a88c1de + ba7525c commit a751a3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/create_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Route } from '../interfaces';
export default function create_routes({ files } = { files: glob.sync('**/*.*', { cwd: locations.routes(), dot: true, nodir: true }) }) {
const routes: Route[] = files
.map((file: string) => {
if (/(^|\/|\\)_/.test(file)) return;
if (/(^|\/|\\)(_|\.(?!well-known))/.test(file)) return;

if (/]\[/.test(file)) {
throw new Error(`Invalid route ${file} — parameters must be separated`);
Expand Down
11 changes: 11 additions & 0 deletions test/unit/create_routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ describe('create_routes', () => {
);
});

it('ignores files and directories with leading dots except .well-known', () => {
const routes = create_routes({
files: ['.well-known', '.unknown']
});

assert.deepEqual(
routes.map(r => r.file),
['.well-known']
);
});

it('matches /foo/:bar before /:baz/qux', () => {
const a = create_routes({
files: ['foo/[bar].html', '[baz]/qux.html']
Expand Down

0 comments on commit a751a3b

Please sign in to comment.