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 #234 from akihikodaki/master
Browse files Browse the repository at this point in the history
Do not encode characters allowed in path when generating routes
  • Loading branch information
Rich-Harris committed May 4, 2018
2 parents a70e88b + b13cc6f commit d7a2132
Show file tree
Hide file tree
Showing 2 changed files with 20 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 @@ -33,7 +33,7 @@ export default function create_routes({ files } = { files: glob.sync('**/*.*', {
let i = parts.length;
let nested = true;
while (i--) {
const part = encodeURIComponent(parts[i].normalize()).replace(/%5B/g, '[').replace(/%5D/g, ']');
const part = encodeURI(parts[i].normalize()).replace(/\?/g, '%3F').replace(/#/g, '%23').replace(/%5B/g, '[').replace(/%5D/g, ']');
const dynamic = ~part.indexOf('[');

if (dynamic) {
Expand Down
19 changes: 19 additions & 0 deletions test/unit/create_routes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@ const assert = require('assert');
const { create_routes } = require('../../dist/core.ts.js');

describe('create_routes', () => {
it('encodes caharcters not allowed in path', () => {
const routes = create_routes({
files: [
'"',
'#',
'?'
]
});

assert.deepEqual(
routes.map(r => r.pattern),
[
/^\/%22\/?$/,
/^\/%23\/?$/,
/^\/%3F\/?$/
]
);
});

it('sorts routes correctly', () => {
const routes = create_routes({
files: ['index.html', 'about.html', 'post/f[xx].html', '[wildcard].html', 'post/foo.html', 'post/[id].html', 'post/bar.html', 'post/[id].json.js']
Expand Down

0 comments on commit d7a2132

Please sign in to comment.