From b13cc6f39a5fd728a06f3166af2e772f00dd0eba Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Sat, 14 Apr 2018 00:56:40 +0900 Subject: [PATCH 1/6] Do not encode characters allowed in path when generating routes In RFC 3986, some characters not allowed in query, which encodeURIComponent is designed for, is allowed in path. A notable example is "@", which is commonly included in paths of social profile pages. Such characters should not be encoded. The new encoding function is conforming to the RFC. --- src/core/create_routes.ts | 2 +- test/unit/create_routes.test.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/core/create_routes.ts b/src/core/create_routes.ts index 3888b87..6fdc7d2 100644 --- a/src/core/create_routes.ts +++ b/src/core/create_routes.ts @@ -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) { diff --git a/test/unit/create_routes.test.js b/test/unit/create_routes.test.js index 5b70ffe..112e95c 100644 --- a/test/unit/create_routes.test.js +++ b/test/unit/create_routes.test.js @@ -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'] From 6f9ce9ce857562d804268be1a7b57474429a86d7 Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Thu, 19 Apr 2018 22:04:03 +0900 Subject: [PATCH 2/6] Accept directory entries which starts with dot as routes It allows to implement .well-known URIs. --- src/core/create_routes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/create_routes.ts b/src/core/create_routes.ts index 3888b87..80ff50f 100644 --- a/src/core/create_routes.ts +++ b/src/core/create_routes.ts @@ -3,7 +3,7 @@ import glob from 'glob'; import { locations } from '../config'; import { Route } from '../interfaces'; -export default function create_routes({ files } = { files: glob.sync('**/*.*', { cwd: locations.routes(), nodir: true }) }) { +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; From a70e88b1f489356c683d71133057a7820b524938 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 19 Apr 2018 13:03:12 -0400 Subject: [PATCH 3/6] -> v0.10.6 --- CHANGELOG.md | 4 ++++ package.json | 2 +- src/cli/start.ts | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a832d6..628be80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # sapper changelog +## 0.10.6 + +* Fix error reporting in `sapper start` + ## 0.10.5 * Fix missing service worker ([#231](https://github.com/sveltejs/sapper/pull/231)) diff --git a/package.json b/package.json index e35f7c6..a118067 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sapper", - "version": "0.10.5", + "version": "0.10.6", "description": "Military-grade apps, engineered by Svelte", "main": "dist/middleware.ts.js", "bin": { diff --git a/src/cli/start.ts b/src/cli/start.ts index 9c3cb85..4f98067 100644 --- a/src/cli/start.ts +++ b/src/cli/start.ts @@ -11,13 +11,13 @@ export async function start(dir: string, opts: { port: number, open: boolean }) const server = path.resolve(dir, 'server.js'); if (!fs.existsSync(server)) { - console.log(clorox.bold.red(`> ${dir}/server.js does not exist — type ${clorox.bold.cyan(dir === 'build' ? `npx sapper build` : `npx sapper build ${dir}`)} to create it`)); + console.log(`${clorox.bold.red(`> ${dir}/server.js does not exist — type ${clorox.bold.cyan(dir === 'build' ? `npx sapper build` : `npx sapper build ${dir}`)} to create it`)}`); return; } if (port) { if (!await ports.check(port)) { - console.log(clorox.bold.red(`> Port ${port} is unavailable`)); + console.log(`${clorox.bold.red(`> Port ${port} is unavailable`)}`); return; } } else { From 37a9fb62e23a281d24b5f160313de4923e1a27ea Mon Sep 17 00:00:00 2001 From: John Muhl Date: Sun, 22 Apr 2018 20:29:47 -0500 Subject: [PATCH 4/6] Include process.env in exporter server options --- src/cli/export.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cli/export.ts b/src/cli/export.ts index 9618c70..99eee4c 100644 --- a/src/cli/export.ts +++ b/src/cli/export.ts @@ -35,12 +35,12 @@ export async function exporter(export_dir: string, { basepath = '' }) { const proc = child_process.fork(path.resolve(`${build_dir}/server.js`), [], { cwd: process.cwd(), - env: { + env: Object.assign({}, process.env, { PORT: port, NODE_ENV: 'production', SAPPER_DEST: build_dir, SAPPER_EXPORT: 'true' - } + }) }); const seen = new Set(); @@ -103,4 +103,4 @@ export async function exporter(export_dir: string, { basepath = '' }) { return ports.wait(port) .then(() => handle(new URL(`/${basepath}`, origin))) // TODO all static routes .then(() => proc.kill()); -} \ No newline at end of file +} From 56ac1aea9d5d91e6edab27410b1642324eccf93f Mon Sep 17 00:00:00 2001 From: John Muhl Date: Sun, 22 Apr 2018 22:50:05 -0500 Subject: [PATCH 5/6] match sapper start --- src/cli/export.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cli/export.ts b/src/cli/export.ts index 99eee4c..07be56e 100644 --- a/src/cli/export.ts +++ b/src/cli/export.ts @@ -35,12 +35,12 @@ export async function exporter(export_dir: string, { basepath = '' }) { const proc = child_process.fork(path.resolve(`${build_dir}/server.js`), [], { cwd: process.cwd(), - env: Object.assign({}, process.env, { + env: Object.assign({ PORT: port, NODE_ENV: 'production', SAPPER_DEST: build_dir, SAPPER_EXPORT: 'true' - }) + }, process.env) }); const seen = new Set(); From 3531cc587dfa0fc595609a5a1f8c17eb364361a4 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 3 May 2018 21:42:50 -0400 Subject: [PATCH 6/6] -> v0.10.7 --- CHANGELOG.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 628be80..6f2a9a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # sapper changelog +## 0.10.7 + +* Allow routes to have a leading `.` ([#243](https://github.com/sveltejs/sapper/pull/243)) +* Only encode necessary characters in routes ([#234](https://github.com/sveltejs/sapper/pull/234)) +* Preserve existing `process.env` when exporting ([#245](https://github.com/sveltejs/sapper/pull/245)) + ## 0.10.6 * Fix error reporting in `sapper start` diff --git a/package.json b/package.json index a118067..2d52c51 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sapper", - "version": "0.10.6", + "version": "0.10.7", "description": "Military-grade apps, engineered by Svelte", "main": "dist/middleware.ts.js", "bin": {