mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-13 19:45:26 +00:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b489f4687 | ||
|
|
91f2c6e49c | ||
|
|
f5e07e9f78 | ||
|
|
17297a9794 | ||
|
|
9ef4f33e38 | ||
|
|
30966ee7f2 | ||
|
|
ae90f774e1 | ||
|
|
0706b5f50a | ||
|
|
499b377bfd | ||
|
|
1baeb79d4b | ||
|
|
0cc5ff95d6 | ||
|
|
e90525c1e8 | ||
|
|
6ccae0cd33 |
10
CHANGELOG.md
10
CHANGELOG.md
@@ -1,5 +1,15 @@
|
||||
# sapper changelog
|
||||
|
||||
## 0.20.0
|
||||
|
||||
* Decode `req.params` and `req.query` ([#417](https://github.com/sveltejs/sapper/issues/417))
|
||||
* Decode URLs before writing files in `sapper export` ([#414](https://github.com/sveltejs/sapper/pull/414))
|
||||
* Generate server sourcemaps for Rollup apps in dev mode ([#418](https://github.com/sveltejs/sapper/pull/418))
|
||||
|
||||
## 0.19.3
|
||||
|
||||
* Better unicode route handling ([#347](https://github.com/sveltejs/sapper/issues/347))
|
||||
|
||||
## 0.19.2
|
||||
|
||||
* Ignore editor tmp files ([#220](https://github.com/sveltejs/sapper/issues/220))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sapper",
|
||||
"version": "0.19.2",
|
||||
"version": "0.20.0",
|
||||
"description": "Military-grade apps, engineered by Svelte",
|
||||
"main": "dist/middleware.js",
|
||||
"bin": {
|
||||
|
||||
@@ -85,7 +85,7 @@ async function execute(emitter: EventEmitter, opts: Opts) {
|
||||
|
||||
function save(path: string, status: number, type: string, body: string) {
|
||||
const { pathname } = resolve(origin, path);
|
||||
let file = pathname.slice(1);
|
||||
let file = decodeURIComponent(pathname.slice(1));
|
||||
|
||||
if (saved.has(file)) return;
|
||||
saved.add(file);
|
||||
|
||||
@@ -63,6 +63,8 @@ function generate_client(
|
||||
import root from '${get_file(path_to_routes, manifest_data.root)}';
|
||||
import error from '${posixify(`${path_to_routes}/_error.html`)}';
|
||||
|
||||
const d = decodeURIComponent;
|
||||
|
||||
${manifest_data.components.map(component => {
|
||||
const annotation = bundler === 'webpack'
|
||||
? `/* webpackChunkName: "${component.name}" */ `
|
||||
@@ -88,7 +90,7 @@ function generate_client(
|
||||
if (part === null) return 'null';
|
||||
|
||||
if (part.params.length > 0) {
|
||||
const props = part.params.map((param, i) => `${param}: match[${i + 1}]`);
|
||||
const props = part.params.map((param, i) => `${param}: d(match[${i + 1}])`);
|
||||
return `{ component: ${part.component.name}, params: match => ({ ${props.join(', ')} }) }`;
|
||||
}
|
||||
|
||||
@@ -138,6 +140,8 @@ function generate_server(
|
||||
// This file is generated by Sapper — do not edit it!
|
||||
${imports.join('\n')}
|
||||
|
||||
const d = decodeURIComponent;
|
||||
|
||||
export const manifest = {
|
||||
server_routes: [
|
||||
${manifest_data.server_routes.map(route => `{
|
||||
@@ -145,7 +149,7 @@ function generate_server(
|
||||
pattern: ${route.pattern},
|
||||
handlers: ${route.name},
|
||||
params: ${route.params.length > 0
|
||||
? `match => ({ ${route.params.map((param, i) => `${param}: match[${i + 1}]`).join(', ')} })`
|
||||
? `match => ({ ${route.params.map((param, i) => `${param}: d(match[${i + 1}])`).join(', ')} })`
|
||||
: `() => ({})`}
|
||||
}`).join(',\n\n\t\t\t\t')}
|
||||
],
|
||||
@@ -165,7 +169,7 @@ function generate_server(
|
||||
];
|
||||
|
||||
if (part.params.length > 0) {
|
||||
const params = part.params.map((param, i) => `${param}: match[${i + 1}]`);
|
||||
const params = part.params.map((param, i) => `${param}: d(match[${i + 1}])`);
|
||||
props.push(`params: match => ({ ${params.join(', ')} })`);
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +185,8 @@ function serve({ prefix, pathname, cache_control }: {
|
||||
const type = lookup(req.path);
|
||||
|
||||
try {
|
||||
const data = read(req.path.slice(1));
|
||||
const file = decodeURIComponent(req.path.slice(1));
|
||||
const data = read(file);
|
||||
|
||||
res.setHeader('Content-Type', type);
|
||||
res.setHeader('Cache-Control', cache_control);
|
||||
|
||||
@@ -30,7 +30,8 @@ export default {
|
||||
output: () => {
|
||||
return {
|
||||
dir: locations.dest(),
|
||||
format: 'cjs'
|
||||
format: 'cjs',
|
||||
sourcemap: dev()
|
||||
};
|
||||
}
|
||||
},
|
||||
|
||||
@@ -67,7 +67,7 @@ function select_route(url: URL): Target {
|
||||
if (url.search.length > 0) {
|
||||
url.search.slice(1).split('&').forEach(searchParam => {
|
||||
const [, key, value] = /([^=]+)=(.*)/.exec(searchParam);
|
||||
query[key] = value || true;
|
||||
query[key] = value ? decodeURIComponent(value.replace(/\+/g, ' ')) : true;
|
||||
});
|
||||
}
|
||||
return { url, path, page, match, query };
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { init, prefetchRoutes } from '../../../runtime.js';
|
||||
import { init, goto, prefetchRoutes } from '../../../runtime.js';
|
||||
import { Store } from 'svelte/store.js';
|
||||
import { manifest } from './manifest/client.js';
|
||||
|
||||
@@ -10,4 +10,5 @@ window.init = () => {
|
||||
});
|
||||
};
|
||||
|
||||
window.prefetchRoutes = prefetchRoutes;
|
||||
window.prefetchRoutes = prefetchRoutes;
|
||||
window.goto = goto;
|
||||
@@ -106,6 +106,14 @@ const posts = [
|
||||
<p>If you didn't have adult onset diabetes, I wouldn't mind giving you a little sugar. Everybody dance NOW. And the soup of the day is bread. Great, now I'm gonna smell to high heaven like a tuna melt!</p>
|
||||
<p>That's how Tony Wonder lost a nut. She calls it a Mayonegg. Go ahead, touch the Cornballer. There's a new daddy in town. A discipline daddy.</p>
|
||||
`
|
||||
},
|
||||
|
||||
{
|
||||
title: 'Encödïng test',
|
||||
slug: 'encödïng-test',
|
||||
html: `
|
||||
<p>It works</p>
|
||||
`
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
12
test/app/routes/echo/page/[slug].html
Normal file
12
test/app/routes/echo/page/[slug].html
Normal file
@@ -0,0 +1,12 @@
|
||||
<h1>{slug} ({message})</h1>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload({ params, query }) {
|
||||
return {
|
||||
slug: params.slug,
|
||||
message: query.message
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
||||
15
test/app/routes/echo/server-route/[slug].js
Normal file
15
test/app/routes/echo/server-route/[slug].js
Normal file
@@ -0,0 +1,15 @@
|
||||
export function get(req, res) {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'text/html'
|
||||
});
|
||||
|
||||
res.end(`
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head><meta charset="utf-8"></head>
|
||||
<body>
|
||||
<h1>${req.params.slug}</h1>
|
||||
</body>
|
||||
</html>
|
||||
`);
|
||||
}
|
||||
@@ -1 +1,11 @@
|
||||
<h1>I'm afraid I just blue myself</h1>
|
||||
<h1>{phrase}</h1>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
return this.fetch('fünke.json').then(r => r.json()).then(phrase => {
|
||||
return { phrase };
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
9
test/app/routes/fünke.json.js
Normal file
9
test/app/routes/fünke.json.js
Normal file
@@ -0,0 +1,9 @@
|
||||
export function get(req, res) {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
res.end(JSON.stringify(
|
||||
"I'm afraid I just blue myself"
|
||||
));
|
||||
}
|
||||
@@ -15,6 +15,7 @@
|
||||
<a href='credentials?creds=include'>credentials</a>
|
||||
<a rel=prefetch class='{page === "blog" ? "selected" : ""}' href='blog'>blog</a>
|
||||
<a href="const">const</a>
|
||||
<a href="echo/page/encöded?message=hëllö+wörld">echo/page/encöded?message=hëllö+wörld</a>
|
||||
|
||||
<div class='hydrate-test'></div>
|
||||
|
||||
|
||||
@@ -93,6 +93,7 @@ function testExport({ basepath = '' }) {
|
||||
'blog/how-to-use-sapper/index.html',
|
||||
'blog/what-is-sapper/index.html',
|
||||
'blog/why-the-name/index.html',
|
||||
'blog/encödïng-test/index.html',
|
||||
|
||||
'blog.json',
|
||||
'blog/a-very-long-post.json',
|
||||
@@ -101,6 +102,7 @@ function testExport({ basepath = '' }) {
|
||||
'blog/how-to-use-sapper.json',
|
||||
'blog/what-is-sapper.json',
|
||||
'blog/why-the-name.json',
|
||||
'blog/encödïng-test.json',
|
||||
|
||||
'favicon.png',
|
||||
'global.css',
|
||||
@@ -746,11 +748,37 @@ function run({ mode, basepath = '' }) {
|
||||
|
||||
it('allows reserved words as route names', () => {
|
||||
return nightmare.goto(`${base}/const`).init()
|
||||
.then(() => nightmare.page.title())
|
||||
.page.title()
|
||||
.then(title => {
|
||||
assert.equal(title, 'reserved words are okay as routes');
|
||||
});
|
||||
});
|
||||
|
||||
it('encodes req.params and req.query for server-rendered pages', () => {
|
||||
return nightmare.goto(`${base}/echo/page/encöded?message=hëllö+wörld`)
|
||||
.page.title()
|
||||
.then(title => {
|
||||
assert.equal(title, 'encöded (hëllö wörld)');
|
||||
});
|
||||
});
|
||||
|
||||
it('encodes req.params and req.query for client-rendered pages', () => {
|
||||
return nightmare.goto(base).init()
|
||||
.click('a[href="echo/page/encöded?message=hëllö+wörld"]')
|
||||
.wait(100)
|
||||
.page.title()
|
||||
.then(title => {
|
||||
assert.equal(title, 'encöded (hëllö wörld)');
|
||||
});
|
||||
});
|
||||
|
||||
it('encodes req.params for server routes', () => {
|
||||
return nightmare.goto(`${base}/echo/server-route/encöded`)
|
||||
.page.title()
|
||||
.then(title => {
|
||||
assert.equal(title, 'encöded');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('headers', () => {
|
||||
|
||||
Reference in New Issue
Block a user