From 80c167c137cfc87b076137365aa5640cfce76fb2 Mon Sep 17 00:00:00 2001 From: Ivan Hofer Date: Fri, 14 Jan 2022 09:59:13 +0100 Subject: [PATCH 1/6] convert redirect uri to URL to prevent encoding the redirect url multiple times --- .../kit/src/core/adapt/prerender/prerender.js | 12 ++++++++++-- .../.svelte-kit/output/server/app.js | 19 +++++++++++++++++-- .../build/redirect-url-encoding/index.html | 1 + .../routes/redirect-url-encoding/index.svelte | 0 packages/kit/src/core/adapt/test/index.js | 18 +++++++++++++++--- 5 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 packages/kit/src/core/adapt/test/fixtures/prerender/build/redirect-url-encoding/index.html create mode 100644 packages/kit/src/core/adapt/test/fixtures/prerender/src/routes/redirect-url-encoding/index.svelte diff --git a/packages/kit/src/core/adapt/prerender/prerender.js b/packages/kit/src/core/adapt/prerender/prerender.js index 5ffb1ac6dc07..e49e1bf739d7 100644 --- a/packages/kit/src/core/adapt/prerender/prerender.js +++ b/packages/kit/src/core/adapt/prerender/prerender.js @@ -167,8 +167,16 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a if (location) { mkdirp(dirname(file)); + let url; + try { + url = new URL(location); + } catch (error) { + log.error(`'${location}' is not a valid URL`); + url = location; + } + log.warn(`${rendered.status} ${decoded_path} -> ${location}`); - writeFileSync(file, ``); + writeFileSync(file, ``); const resolved = resolve(path, location); if (is_root_relative(resolved)) { @@ -222,7 +230,7 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a }); if (is_html && config.kit.prerender.crawl) { - for (const href of crawl(/** @type {string} */ (rendered.body))) { + for (const href of crawl(/** @type {string} */(rendered.body))) { if (href.startsWith('data:')) continue; const resolved = resolve(path, href); diff --git a/packages/kit/src/core/adapt/test/fixtures/prerender/.svelte-kit/output/server/app.js b/packages/kit/src/core/adapt/test/fixtures/prerender/.svelte-kit/output/server/app.js index a59d5d30f0a5..8b1aef05bcdb 100644 --- a/packages/kit/src/core/adapt/test/fixtures/prerender/.svelte-kit/output/server/app.js +++ b/packages/kit/src/core/adapt/test/fixtures/prerender/.svelte-kit/output/server/app.js @@ -1,5 +1,20 @@ +function redirectResponse() { + const urlSearchParams = new URLSearchParams({ 'redirect': 'https://kit.svelte.dev/docs' }) + + const redirectTo = `https://my.server.com/?${urlSearchParams.toString()}` + + return { + status: 302, + headers: { + location: redirectTo + } + } +} + export class App { - render() { + render({ url }) { + if (url === 'http://prerender/redirect-url-encoding') return redirectResponse() + return { status: 200, headers: { @@ -10,4 +25,4 @@ export class App { } } -export function override() {} +export function override() { } diff --git a/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirect-url-encoding/index.html b/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirect-url-encoding/index.html new file mode 100644 index 000000000000..f38b6b7013b4 --- /dev/null +++ b/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirect-url-encoding/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/kit/src/core/adapt/test/fixtures/prerender/src/routes/redirect-url-encoding/index.svelte b/packages/kit/src/core/adapt/test/fixtures/prerender/src/routes/redirect-url-encoding/index.svelte new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/kit/src/core/adapt/test/index.js b/packages/kit/src/core/adapt/test/index.js index 2c212dee5055..934a2621ebe8 100644 --- a/packages/kit/src/core/adapt/test/index.js +++ b/packages/kit/src/core/adapt/test/index.js @@ -1,4 +1,4 @@ -import { rmSync } from 'fs'; +import { readFileSync, rmSync } from 'fs'; import { join } from 'path'; import * as uvu from 'uvu'; import * as assert from 'uvu/assert'; @@ -112,7 +112,7 @@ suite('prerender', async () => { // @ts-expect-error server: { chunks: [] }, static: [], - entries: ['/nested'] + entries: ['/nested', '/redirect-url-encoding'] }; const builder = create_builder({ @@ -130,7 +130,19 @@ suite('prerender', async () => { dest }); - assert.equal(glob('**', { cwd: prerendered_files }), glob('**', { cwd: dest })); + const expectedFiles = glob('**', { cwd: prerendered_files }); + const actualFiles = glob('**', { cwd: dest }); + + // test if all files are present + assert.equal(expectedFiles, actualFiles); + + // check each file if content is correct + for (const file of expectedFiles.filter(file => file.endsWith('.html'))) { + const expectedContent = readFileSync(join(prerendered_files, file)); + const actualContent = readFileSync(join(dest, file)); + + assert.equal(actualContent.toString(), expectedContent.toString()); + } rmSync(dest, { recursive: true, force: true }); }); From 817945d12fd0bf6df36bd72c5d568037050053e6 Mon Sep 17 00:00:00 2001 From: Ivan Hofer Date: Fri, 14 Jan 2022 14:04:46 +0100 Subject: [PATCH 2/6] run prettier+eslint --- packages/kit/src/core/adapt/prerender/prerender.js | 2 +- .../prerender/.svelte-kit/output/server/app.js | 10 +++++----- packages/kit/src/core/adapt/test/index.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/kit/src/core/adapt/prerender/prerender.js b/packages/kit/src/core/adapt/prerender/prerender.js index e49e1bf739d7..1850c954893d 100644 --- a/packages/kit/src/core/adapt/prerender/prerender.js +++ b/packages/kit/src/core/adapt/prerender/prerender.js @@ -230,7 +230,7 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a }); if (is_html && config.kit.prerender.crawl) { - for (const href of crawl(/** @type {string} */(rendered.body))) { + for (const href of crawl(/** @type {string} */ (rendered.body))) { if (href.startsWith('data:')) continue; const resolved = resolve(path, href); diff --git a/packages/kit/src/core/adapt/test/fixtures/prerender/.svelte-kit/output/server/app.js b/packages/kit/src/core/adapt/test/fixtures/prerender/.svelte-kit/output/server/app.js index 8b1aef05bcdb..cd9c972e42c8 100644 --- a/packages/kit/src/core/adapt/test/fixtures/prerender/.svelte-kit/output/server/app.js +++ b/packages/kit/src/core/adapt/test/fixtures/prerender/.svelte-kit/output/server/app.js @@ -1,19 +1,19 @@ function redirectResponse() { - const urlSearchParams = new URLSearchParams({ 'redirect': 'https://kit.svelte.dev/docs' }) + const urlSearchParams = new URLSearchParams({ redirect: 'https://kit.svelte.dev/docs' }); - const redirectTo = `https://my.server.com/?${urlSearchParams.toString()}` + const redirectTo = `https://my.server.com/?${urlSearchParams.toString()}`; return { status: 302, headers: { location: redirectTo } - } + }; } export class App { render({ url }) { - if (url === 'http://prerender/redirect-url-encoding') return redirectResponse() + if (url === 'http://prerender/redirect-url-encoding') return redirectResponse(); return { status: 200, @@ -25,4 +25,4 @@ export class App { } } -export function override() { } +export function override() {} diff --git a/packages/kit/src/core/adapt/test/index.js b/packages/kit/src/core/adapt/test/index.js index 934a2621ebe8..96e891360699 100644 --- a/packages/kit/src/core/adapt/test/index.js +++ b/packages/kit/src/core/adapt/test/index.js @@ -137,7 +137,7 @@ suite('prerender', async () => { assert.equal(expectedFiles, actualFiles); // check each file if content is correct - for (const file of expectedFiles.filter(file => file.endsWith('.html'))) { + for (const file of expectedFiles.filter((file) => file.endsWith('.html'))) { const expectedContent = readFileSync(join(prerendered_files, file)); const actualContent = readFileSync(join(dest, file)); From d9726986e4e908e329e2b66f2becc7975e71f65a Mon Sep 17 00:00:00 2001 From: Ivan Hofer Date: Sun, 16 Jan 2022 10:58:17 +0100 Subject: [PATCH 3/6] take into account different url types --- .../kit/src/core/adapt/prerender/prerender.js | 42 +++++++++++++------ .../.svelte-kit/output/server/app.js | 22 +++++++--- .../redirected/index.html} | 0 .../absolute-url/encoding}/index.html | 0 .../absolute-url/no-encoding/index.html | 1 + .../redirects/path-url/encoding/index.html | 1 + .../redirects/path-url/no-encoding/index.html | 1 + .../relative-url/encoding/index.html | 1 + .../relative-url/no-encoding/index.html | 1 + .../routes/redirect-url-encoding/index.svelte | 0 packages/kit/src/core/adapt/test/index.js | 20 ++++++--- 11 files changed, 65 insertions(+), 24 deletions(-) rename packages/kit/src/core/adapt/test/fixtures/prerender/{src/routes/nested/index.svelte => build/redirected/index.html} (100%) rename packages/kit/src/core/adapt/test/fixtures/prerender/build/{redirect-url-encoding => redirects/absolute-url/encoding}/index.html (100%) create mode 100644 packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/absolute-url/no-encoding/index.html create mode 100644 packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/path-url/encoding/index.html create mode 100644 packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/path-url/no-encoding/index.html create mode 100644 packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/relative-url/encoding/index.html create mode 100644 packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/relative-url/no-encoding/index.html delete mode 100644 packages/kit/src/core/adapt/test/fixtures/prerender/src/routes/redirect-url-encoding/index.svelte diff --git a/packages/kit/src/core/adapt/prerender/prerender.js b/packages/kit/src/core/adapt/prerender/prerender.js index 1850c954893d..61aaa24367da 100644 --- a/packages/kit/src/core/adapt/prerender/prerender.js +++ b/packages/kit/src/core/adapt/prerender/prerender.js @@ -98,6 +98,7 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a /** * @param {string} path + * @returns string */ function normalize(path) { if (config.kit.trailingSlash === 'always') { @@ -109,6 +110,28 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a return path; } + /** + * @param {string} path + * @returns string + */ + function remove_query_string(path) { + return path.split('?')[0]; + } + + + /** @type {(location: string) => string} */ + function encode_location(location) { + const is_relative_url = location.startsWith('.') || location.startsWith('/'); + if (is_relative_url) { + + const protocol = 'http://'; + return new URL(protocol + location).toString().substring(protocol.length); + } + + return new URL(location).toString(); + } + + const q = queue(config.kit.prerender.concurrency); /** @@ -116,12 +139,13 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a * @param {string?} referrer */ function enqueue(decoded_path, referrer) { - const path = encodeURI(normalize(decoded_path)); + const decoded_path_without_query_string = remove_query_string(decoded_path); + const path = encodeURI(normalize(decoded_path_without_query_string)); if (seen.has(path)) return; seen.add(path); - return q.add(() => visit(path, decoded_path, referrer)); + return q.add(() => visit(path, decoded_path_without_query_string, referrer)); } /** @@ -167,16 +191,10 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a if (location) { mkdirp(dirname(file)); - let url; - try { - url = new URL(location); - } catch (error) { - log.error(`'${location}' is not a valid URL`); - url = location; - } + const encoded_location = encode_location(location); log.warn(`${rendered.status} ${decoded_path} -> ${location}`); - writeFileSync(file, ``); + writeFileSync(file, ``); const resolved = resolve(path, location); if (is_root_relative(resolved)) { @@ -214,7 +232,7 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a if (result.body) { writeFileSync(file, result.body); - paths.push(dependency_path); + paths.push(normalize(dependency_path)); } if (response_type === OK) { @@ -230,7 +248,7 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a }); if (is_html && config.kit.prerender.crawl) { - for (const href of crawl(/** @type {string} */ (rendered.body))) { + for (const href of crawl(/** @type {string} */(rendered.body))) { if (href.startsWith('data:')) continue; const resolved = resolve(path, href); diff --git a/packages/kit/src/core/adapt/test/fixtures/prerender/.svelte-kit/output/server/app.js b/packages/kit/src/core/adapt/test/fixtures/prerender/.svelte-kit/output/server/app.js index cd9c972e42c8..ae2dce48556f 100644 --- a/packages/kit/src/core/adapt/test/fixtures/prerender/.svelte-kit/output/server/app.js +++ b/packages/kit/src/core/adapt/test/fixtures/prerender/.svelte-kit/output/server/app.js @@ -1,19 +1,29 @@ -function redirectResponse() { - const urlSearchParams = new URLSearchParams({ redirect: 'https://kit.svelte.dev/docs' }); +function get_redirect_response(url) { + const [, , , , url_type, encoding_style] = url.split('/') - const redirectTo = `https://my.server.com/?${urlSearchParams.toString()}`; + const base_url = (() => { + switch (url_type) { + case 'absolute-url': return 'https://my.server.com/'; + case 'path-url': return './../../redirected'; + case 'relative-url': return '/redirected'; + } + })() + + const search_params = encoding_style === 'encoding' + ? new URLSearchParams({ redirect: 'https://kit.svelte.dev/docs' }).toString() + : 'redirect=https://kit.svelte.dev/docs'; return { status: 302, headers: { - location: redirectTo + location: `${base_url}?${search_params}` } }; } export class App { render({ url }) { - if (url === 'http://prerender/redirect-url-encoding') return redirectResponse(); + if (url.startsWith('http://prerender/redirects/')) return get_redirect_response(url) return { status: 200, @@ -25,4 +35,4 @@ export class App { } } -export function override() {} +export function override() { } diff --git a/packages/kit/src/core/adapt/test/fixtures/prerender/src/routes/nested/index.svelte b/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirected/index.html similarity index 100% rename from packages/kit/src/core/adapt/test/fixtures/prerender/src/routes/nested/index.svelte rename to packages/kit/src/core/adapt/test/fixtures/prerender/build/redirected/index.html diff --git a/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirect-url-encoding/index.html b/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/absolute-url/encoding/index.html similarity index 100% rename from packages/kit/src/core/adapt/test/fixtures/prerender/build/redirect-url-encoding/index.html rename to packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/absolute-url/encoding/index.html diff --git a/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/absolute-url/no-encoding/index.html b/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/absolute-url/no-encoding/index.html new file mode 100644 index 000000000000..1a5bb3d25abb --- /dev/null +++ b/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/absolute-url/no-encoding/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/path-url/encoding/index.html b/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/path-url/encoding/index.html new file mode 100644 index 000000000000..0dd022727b4d --- /dev/null +++ b/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/path-url/encoding/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/path-url/no-encoding/index.html b/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/path-url/no-encoding/index.html new file mode 100644 index 000000000000..24d828054c0a --- /dev/null +++ b/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/path-url/no-encoding/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/relative-url/encoding/index.html b/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/relative-url/encoding/index.html new file mode 100644 index 000000000000..a28bb0712d34 --- /dev/null +++ b/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/relative-url/encoding/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/relative-url/no-encoding/index.html b/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/relative-url/no-encoding/index.html new file mode 100644 index 000000000000..eb2591dc4bfe --- /dev/null +++ b/packages/kit/src/core/adapt/test/fixtures/prerender/build/redirects/relative-url/no-encoding/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/kit/src/core/adapt/test/fixtures/prerender/src/routes/redirect-url-encoding/index.svelte b/packages/kit/src/core/adapt/test/fixtures/prerender/src/routes/redirect-url-encoding/index.svelte deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/packages/kit/src/core/adapt/test/index.js b/packages/kit/src/core/adapt/test/index.js index 96e891360699..177b24e31792 100644 --- a/packages/kit/src/core/adapt/test/index.js +++ b/packages/kit/src/core/adapt/test/index.js @@ -11,7 +11,7 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = join(__filename, '..'); /** @param {string} _msg */ -const logger = (_msg) => {}; +const logger = (_msg) => { }; /** @type {import('types/internal').Logger} */ const log = Object.assign(logger, { @@ -112,7 +112,15 @@ suite('prerender', async () => { // @ts-expect-error server: { chunks: [] }, static: [], - entries: ['/nested', '/redirect-url-encoding'] + entries: [ + '/nested', + '/redirects/absolute-url/no-encoding', + '/redirects/absolute-url/encoding', + '/redirects/path-url/no-encoding', + '/redirects/path-url/encoding', + '/redirects/relative-url/no-encoding', + '/redirects/relative-url/encoding' + ] }; const builder = create_builder({ @@ -134,14 +142,14 @@ suite('prerender', async () => { const actualFiles = glob('**', { cwd: dest }); // test if all files are present - assert.equal(expectedFiles, actualFiles); + assert.equal(actualFiles, expectedFiles); // check each file if content is correct for (const file of expectedFiles.filter((file) => file.endsWith('.html'))) { - const expectedContent = readFileSync(join(prerendered_files, file)); - const actualContent = readFileSync(join(dest, file)); + const expected_content = readFileSync(join(prerendered_files, file)); + const actual_content = readFileSync(join(dest, file)); - assert.equal(actualContent.toString(), expectedContent.toString()); + assert.equal(actual_content.toString(), expected_content.toString(), `content of '${file}' is not equal`); } rmSync(dest, { recursive: true, force: true }); From 296a3aeab0c3005baec318497566403fed635f4f Mon Sep 17 00:00:00 2001 From: Ivan Hofer Date: Sun, 16 Jan 2022 11:15:03 +0100 Subject: [PATCH 4/6] fix lint issues --- .prettierrc | 8 +++++++ .../kit/src/core/adapt/prerender/prerender.js | 5 +--- .../.svelte-kit/output/server/app.js | 24 +++++++++++-------- packages/kit/src/core/adapt/test/index.js | 8 +++++-- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/.prettierrc b/.prettierrc index 96f5919856ba..5c6c8539122e 100644 --- a/.prettierrc +++ b/.prettierrc @@ -21,6 +21,14 @@ "options": { "requirePragma": true } + }, + { + "files": [ + "packages/kit/src/core/adapt/test/fixtures/**/*.html" + ], + "options": { + "requirePragma": true + } } ] } diff --git a/packages/kit/src/core/adapt/prerender/prerender.js b/packages/kit/src/core/adapt/prerender/prerender.js index 61aaa24367da..52845fb60cf3 100644 --- a/packages/kit/src/core/adapt/prerender/prerender.js +++ b/packages/kit/src/core/adapt/prerender/prerender.js @@ -118,12 +118,10 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a return path.split('?')[0]; } - /** @type {(location: string) => string} */ function encode_location(location) { const is_relative_url = location.startsWith('.') || location.startsWith('/'); if (is_relative_url) { - const protocol = 'http://'; return new URL(protocol + location).toString().substring(protocol.length); } @@ -131,7 +129,6 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a return new URL(location).toString(); } - const q = queue(config.kit.prerender.concurrency); /** @@ -248,7 +245,7 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a }); if (is_html && config.kit.prerender.crawl) { - for (const href of crawl(/** @type {string} */(rendered.body))) { + for (const href of crawl(/** @type {string} */ (rendered.body))) { if (href.startsWith('data:')) continue; const resolved = resolve(path, href); diff --git a/packages/kit/src/core/adapt/test/fixtures/prerender/.svelte-kit/output/server/app.js b/packages/kit/src/core/adapt/test/fixtures/prerender/.svelte-kit/output/server/app.js index ae2dce48556f..73145fbfb36f 100644 --- a/packages/kit/src/core/adapt/test/fixtures/prerender/.svelte-kit/output/server/app.js +++ b/packages/kit/src/core/adapt/test/fixtures/prerender/.svelte-kit/output/server/app.js @@ -1,17 +1,21 @@ function get_redirect_response(url) { - const [, , , , url_type, encoding_style] = url.split('/') + const [, , , , url_type, encoding_style] = url.split('/'); const base_url = (() => { switch (url_type) { - case 'absolute-url': return 'https://my.server.com/'; - case 'path-url': return './../../redirected'; - case 'relative-url': return '/redirected'; + case 'absolute-url': + return 'https://my.server.com/'; + case 'path-url': + return './../../redirected'; + case 'relative-url': + return '/redirected'; } - })() + })(); - const search_params = encoding_style === 'encoding' - ? new URLSearchParams({ redirect: 'https://kit.svelte.dev/docs' }).toString() - : 'redirect=https://kit.svelte.dev/docs'; + const search_params = + encoding_style === 'encoding' + ? new URLSearchParams({ redirect: 'https://kit.svelte.dev/docs' }).toString() + : 'redirect=https://kit.svelte.dev/docs'; return { status: 302, @@ -23,7 +27,7 @@ function get_redirect_response(url) { export class App { render({ url }) { - if (url.startsWith('http://prerender/redirects/')) return get_redirect_response(url) + if (url.startsWith('http://prerender/redirects/')) return get_redirect_response(url); return { status: 200, @@ -35,4 +39,4 @@ export class App { } } -export function override() { } +export function override() {} diff --git a/packages/kit/src/core/adapt/test/index.js b/packages/kit/src/core/adapt/test/index.js index 177b24e31792..ff4d6b424dfb 100644 --- a/packages/kit/src/core/adapt/test/index.js +++ b/packages/kit/src/core/adapt/test/index.js @@ -11,7 +11,7 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = join(__filename, '..'); /** @param {string} _msg */ -const logger = (_msg) => { }; +const logger = (_msg) => {}; /** @type {import('types/internal').Logger} */ const log = Object.assign(logger, { @@ -149,7 +149,11 @@ suite('prerender', async () => { const expected_content = readFileSync(join(prerendered_files, file)); const actual_content = readFileSync(join(dest, file)); - assert.equal(actual_content.toString(), expected_content.toString(), `content of '${file}' is not equal`); + assert.equal( + actual_content.toString(), + expected_content.toString(), + `content of '${file}' is not equal` + ); } rmSync(dest, { recursive: true, force: true }); From 3a9fc7baf8bede5dcd04686e38c4f1ff5894973a Mon Sep 17 00:00:00 2001 From: Ivan Hofer Date: Sun, 16 Jan 2022 11:20:04 +0100 Subject: [PATCH 5/6] rename to snake_case --- packages/kit/src/core/adapt/test/index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/kit/src/core/adapt/test/index.js b/packages/kit/src/core/adapt/test/index.js index ff4d6b424dfb..6b15b9df0ba1 100644 --- a/packages/kit/src/core/adapt/test/index.js +++ b/packages/kit/src/core/adapt/test/index.js @@ -138,14 +138,14 @@ suite('prerender', async () => { dest }); - const expectedFiles = glob('**', { cwd: prerendered_files }); - const actualFiles = glob('**', { cwd: dest }); + const expected = glob('**', { cwd: prerendered_files }); + const files = glob('**', { cwd: dest }); // test if all files are present - assert.equal(actualFiles, expectedFiles); + assert.equal(files, expected); // check each file if content is correct - for (const file of expectedFiles.filter((file) => file.endsWith('.html'))) { + for (const file of expected.filter((file) => file.endsWith('.html'))) { const expected_content = readFileSync(join(prerendered_files, file)); const actual_content = readFileSync(join(dest, file)); From d77e6a0a0462ae77408b43ffff88d7f5a0862781 Mon Sep 17 00:00:00 2001 From: Ivan Hofer Date: Sun, 16 Jan 2022 11:25:17 +0100 Subject: [PATCH 6/6] add changeset --- .changeset/green-rings-pump.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/green-rings-pump.md diff --git a/.changeset/green-rings-pump.md b/.changeset/green-rings-pump.md new file mode 100644 index 000000000000..a5c963bd4460 --- /dev/null +++ b/.changeset/green-rings-pump.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +[fix] don't encode redirects multiple times