Skip to content

Commit

Permalink
fix: always default paths.assets to paths.base (#8928)
Browse files Browse the repository at this point in the history
* Make sure that prerendering visitation code doesn't accidentally move outside the base path + add tests [1/2]

* Make sure that prerendering visitation code doesn't accidentally move outside the base path + add tests [2/2]

* Add changeset

* Don’t specify default in test

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>

* fix

* Update .changeset/smooth-shrimps-look.md

---------

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
Co-authored-by: Rich Harris <hello@rich-harris.dev>
  • Loading branch information
3 people authored Feb 8, 2023
1 parent ae07a39 commit c983428
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/smooth-shrimps-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: always default `paths.assets` to `paths.base`
2 changes: 1 addition & 1 deletion packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ function kit({ svelte_config }) {
case '\0$internal/paths':
const { assets, base } = svelte_config.kit.paths;
return `export const base = ${s(base)};
export let assets = ${s(assets)};
export let assets = ${assets ? s(assets) : 'base'};
/** @param {string} path */
export function set_assets(path) {
Expand Down
1 change: 1 addition & 0 deletions packages/kit/test/prerendering/paths-base/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
%sveltekit.head%
</head>
<body>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import { base } from '$app/paths'
</script>

<div>
<h1>Main Page</h1>
<a href="{base}/nested">Nested Link</a>
</div>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions packages/kit/test/prerendering/paths-base/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const read = (file) => fs.readFileSync(`${build}/${file}`, 'utf-8');

test('prerenders /path-base', () => {
const content = read('index.html');
assert.ok(content.includes('/path-base/favicon.png') && content.includes('/path-base/nested'));
});

test('prerenders /path-base/redirect', () => {
const content = read('redirect.html');
assert.equal(content, '<meta http-equiv="refresh" content="0;url=/path-base/dynamic/foo">');
});

Expand Down

0 comments on commit c983428

Please sign in to comment.