Skip to content

fix: avoid errors when constructing the base path in certain edge cases #13231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/yellow-bags-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: avoid errors when constructing the base path in certain edge cases
5 changes: 3 additions & 2 deletions packages/kit/src/runtime/server/page/render.js
Original file line number Diff line number Diff line change
@@ -102,14 +102,15 @@ export async function render_response({
base = segments.map(() => '..').join('/') || '.';

// resolve e.g. '../..' against current location, then remove trailing slash
base_expression = `new URL(${s(base)}, location).pathname.slice(0, -1)`;
base_expression = `['about:', 'data:'].includes(location.protocol) ? ${s(base)} : new URL(${s(base)}, location).pathname.slice(0, -1)`;

if (!paths.assets || (paths.assets[0] === '/' && paths.assets !== SVELTE_KIT_ASSETS)) {
assets = base;
}
} else if (options.hash_routing) {
// we have to assume that we're in the right place
base_expression = "new URL('.', location).pathname.slice(0, -1)";
base_expression =
"['about:', 'data:'].includes(location.protocol) ? '' : new URL('.', location).pathname.slice(0, -1)";
}
}


Unchanged files with check annotations Beta

expect(page.locator('p.loadingfail')).toBeHidden();
});
test('Catches fetch errors from server load functions (direct hit)', async ({ page }) => {

Check warning on line 1007 in packages/kit/test/apps/basics/test/client.test.js

GitHub Actions / test-kit (20, ubuntu-latest, chromium)

flaky test: Catches fetch errors from server load functions (direct hit)

retries: 2

Check warning on line 1007 in packages/kit/test/apps/basics/test/client.test.js

GitHub Actions / test-kit (22, ubuntu-latest, chromium)

flaky test: Catches fetch errors from server load functions (direct hit)

retries: 2
page.goto('/streaming/server-error');
await expect(page.locator('p.eager')).toHaveText('eager');
await expect(page.locator('p.fail')).toHaveText('fail');
test.describe('Filesystem updates', () => {
if (process.env.DEV) {
test('New route is immediately available in dev', async ({ page }) => {

Check warning on line 14 in packages/kit/test/apps/writes/test/test.js

GitHub Actions / test-kit (22, ubuntu-latest, chromium)

flaky test: New route is immediately available in dev

retries: 2
await page.goto('/new-route');
// hash the filename so that it won't conflict with
expect(await page.textContent('h1')).toBe('test-slug');
});
test('does not attempt client-side navigation to server routes', async ({ page }) => {

Check warning on line 690 in packages/kit/test/apps/basics/test/cross-platform/test.js

GitHub Actions / test-kit-cross-browser (18, windows-2019, chromium, build)

flaky test: does not attempt client-side navigation to server routes

retries: 2
await page.goto('/routing');
await page.locator('[href="/routing/ambiguous/ok.json"]').click();
expect(await page.textContent('body')).toBe('ok');
expect(await page.textContent('h3')).toBe('bar');
});
test('responds to <form target="_blank"> submission with new tab', async ({ page }) => {

Check warning on line 831 in packages/kit/test/apps/basics/test/cross-platform/client.test.js

GitHub Actions / test-kit-cross-browser (18, ubuntu-latest, firefox, build)

flaky test: responds to <form target="_blank"> submission with new tab

retries: 2
await page.goto('/routing/form-target-blank');
let tabs = page.context().pages();