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

Commit 1af0f13

Browse files
committed
Merge branch 'master' into gh-262
2 parents 80ece8b + b75ae7b commit 1af0f13

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# sapper changelog
22

3+
## 0.14.2
4+
5+
* Prevent unsafe replacements ([#307](https://github.com/sveltejs/sapper/pull/307))
6+
37
## 0.14.1
48

59
* Route parameters can be qualified with regex characters ([#283](https://github.com/sveltejs/sapper/pull/283))

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sapper",
3-
"version": "0.14.1",
3+
"version": "0.14.2",
44
"description": "Military-grade apps, engineered by Svelte",
55
"main": "dist/middleware.ts.js",
66
"bin": {

src/middleware.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,11 @@ function get_page_handler(routes: RouteObject[], store_getter: (req: Req) => Sto
355355
}
356356

357357
const page = template()
358-
.replace('%sapper.base%', `<base href="${req.baseUrl}/">`)
359-
.replace('%sapper.scripts%', `<script>${inline_script}</script>${scripts}`)
360-
.replace('%sapper.html%', html)
361-
.replace('%sapper.head%', `<noscript id='sapper-head-start'></noscript>${head}<noscript id='sapper-head-end'></noscript>`)
362-
.replace('%sapper.styles%', (css && css.code ? `<style>${css.code}</style>` : ''));
358+
.replace('%sapper.base%', () => `<base href="${req.baseUrl}/">`)
359+
.replace('%sapper.scripts%', () => `<script>${inline_script}</script>${scripts}`)
360+
.replace('%sapper.html%', () => html)
361+
.replace('%sapper.head%', () => `<noscript id='sapper-head-start'></noscript>${head}<noscript id='sapper-head-end'></noscript>`)
362+
.replace('%sapper.styles%', () => (css && css.code ? `<style>${css.code}</style>` : ''));
363363

364364
res.statusCode = status;
365365
res.end(page);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
$&
2+
3+
<script>
4+
export default {
5+
preload() {
6+
return '$&';
7+
}
8+
};
9+
</script>

test/common/test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,16 @@ function run({ mode, basepath = '' }) {
619619
assert.equal(name, 'BODY');
620620
});
621621
});
622+
623+
it('replaces %sapper.xxx% tags safely', () => {
624+
return nightmare
625+
.goto(`${base}/unsafe-replacement`)
626+
.init()
627+
.page.html()
628+
.then(html => {
629+
assert.equal(html.indexOf('%sapper'), -1);
630+
});
631+
});
622632
});
623633

624634
describe('headers', () => {

0 commit comments

Comments
 (0)