@sveltejs/kit 1.0.0-next.237 → 1.0.0-next.238

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,8 +6,8 @@ import { c as coalesce_to_error, S as SVELTE_KIT_ASSETS, r as resolve_entry, $,
6
6
  import fs__default from 'fs';
7
7
  import { URL as URL$1 } from 'url';
8
8
  import { t as to_headers, s as sirv } from './http.js';
9
+ import { e as escape_html_attr, r as resolve, i as is_root_relative, a as escape_json_string_in_html } from './url.js';
9
10
  import { s } from './misc.js';
10
- import { r as resolve, i as is_root_relative } from './url.js';
11
11
  import { __fetch_polyfill } from '../install-fetch.js';
12
12
  import { getRawBody, setResponse } from '../node.js';
13
13
  import 'sade';
@@ -463,85 +463,6 @@ function writable(value, start = noop) {
463
463
  return { set, update, subscribe };
464
464
  }
465
465
 
466
- /** @type {Record<string, string>} */
467
- const escape_json_string_in_html_dict = {
468
- '"': '\\"',
469
- '<': '\\u003C',
470
- '>': '\\u003E',
471
- '/': '\\u002F',
472
- '\\': '\\\\',
473
- '\b': '\\b',
474
- '\f': '\\f',
475
- '\n': '\\n',
476
- '\r': '\\r',
477
- '\t': '\\t',
478
- '\0': '\\0',
479
- '\u2028': '\\u2028',
480
- '\u2029': '\\u2029'
481
- };
482
-
483
- /** @param {string} str */
484
- function escape_json_string_in_html(str) {
485
- return escape(
486
- str,
487
- escape_json_string_in_html_dict,
488
- (code) => `\\u${code.toString(16).toUpperCase()}`
489
- );
490
- }
491
-
492
- /** @type {Record<string, string>} */
493
- const escape_html_attr_dict = {
494
- '<': '&lt;',
495
- '>': '&gt;',
496
- '"': '&quot;'
497
- };
498
-
499
- /**
500
- * use for escaping string values to be used html attributes on the page
501
- * e.g.
502
- * <script data-url="here">
503
- *
504
- * @param {string} str
505
- * @returns string escaped string
506
- */
507
- function escape_html_attr(str) {
508
- return '"' + escape(str, escape_html_attr_dict, (code) => `&#${code};`) + '"';
509
- }
510
-
511
- /**
512
- *
513
- * @param str {string} string to escape
514
- * @param dict {Record<string, string>} dictionary of character replacements
515
- * @param unicode_encoder {function(number): string} encoder to use for high unicode characters
516
- * @returns {string}
517
- */
518
- function escape(str, dict, unicode_encoder) {
519
- let result = '';
520
-
521
- for (let i = 0; i < str.length; i += 1) {
522
- const char = str.charAt(i);
523
- const code = char.charCodeAt(0);
524
-
525
- if (char in dict) {
526
- result += dict[char];
527
- } else if (code >= 0xd800 && code <= 0xdfff) {
528
- const next = str.charCodeAt(i + 1);
529
-
530
- // If this is the beginning of a [high, low] surrogate pair,
531
- // add the next two characters, otherwise escape
532
- if (code <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
533
- result += char + str[++i];
534
- } else {
535
- result += unicode_encoder(code);
536
- }
537
- } else {
538
- result += char;
539
- }
540
- }
541
-
542
- return result;
543
- }
544
-
545
466
  /** @param {URL} url */
546
467
  function create_prerendering_url_proxy(url) {
547
468
  return new Proxy(url, {
@@ -3,7 +3,7 @@ import { readFileSync, writeFileSync } from 'fs';
3
3
  import { resolve, join, dirname } from 'path';
4
4
  import { pathToFileURL, URL } from 'url';
5
5
  import { __fetch_polyfill } from '../install-fetch.js';
6
- import { r as resolve$1, i as is_root_relative } from './url.js';
6
+ import { e as escape_html_attr, r as resolve$1, i as is_root_relative } from './url.js';
7
7
  import { g as generate_manifest } from './index4.js';
8
8
  import 'sade';
9
9
  import 'child_process';
@@ -441,7 +441,11 @@ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
441
441
  mkdirp(dirname(file));
442
442
 
443
443
  log.warn(`${rendered.status} ${decoded_path} -> ${location}`);
444
- writeFileSync(file, `<meta http-equiv="refresh" content="0;url=${encodeURI(location)}">`);
444
+
445
+ writeFileSync(
446
+ file,
447
+ `<meta http-equiv="refresh" content=${escape_html_attr(`0;url=${location}`)}>`
448
+ );
445
449
 
446
450
  const resolved = resolve$1(path, location);
447
451
  if (is_root_relative(resolved)) {
@@ -1,3 +1,82 @@
1
+ /** @type {Record<string, string>} */
2
+ const escape_json_string_in_html_dict = {
3
+ '"': '\\"',
4
+ '<': '\\u003C',
5
+ '>': '\\u003E',
6
+ '/': '\\u002F',
7
+ '\\': '\\\\',
8
+ '\b': '\\b',
9
+ '\f': '\\f',
10
+ '\n': '\\n',
11
+ '\r': '\\r',
12
+ '\t': '\\t',
13
+ '\0': '\\0',
14
+ '\u2028': '\\u2028',
15
+ '\u2029': '\\u2029'
16
+ };
17
+
18
+ /** @param {string} str */
19
+ function escape_json_string_in_html(str) {
20
+ return escape(
21
+ str,
22
+ escape_json_string_in_html_dict,
23
+ (code) => `\\u${code.toString(16).toUpperCase()}`
24
+ );
25
+ }
26
+
27
+ /** @type {Record<string, string>} */
28
+ const escape_html_attr_dict = {
29
+ '<': '&lt;',
30
+ '>': '&gt;',
31
+ '"': '&quot;'
32
+ };
33
+
34
+ /**
35
+ * use for escaping string values to be used html attributes on the page
36
+ * e.g.
37
+ * <script data-url="here">
38
+ *
39
+ * @param {string} str
40
+ * @returns string escaped string
41
+ */
42
+ function escape_html_attr(str) {
43
+ return '"' + escape(str, escape_html_attr_dict, (code) => `&#${code};`) + '"';
44
+ }
45
+
46
+ /**
47
+ *
48
+ * @param str {string} string to escape
49
+ * @param dict {Record<string, string>} dictionary of character replacements
50
+ * @param unicode_encoder {function(number): string} encoder to use for high unicode characters
51
+ * @returns {string}
52
+ */
53
+ function escape(str, dict, unicode_encoder) {
54
+ let result = '';
55
+
56
+ for (let i = 0; i < str.length; i += 1) {
57
+ const char = str.charAt(i);
58
+ const code = char.charCodeAt(0);
59
+
60
+ if (char in dict) {
61
+ result += dict[char];
62
+ } else if (code >= 0xd800 && code <= 0xdfff) {
63
+ const next = str.charCodeAt(i + 1);
64
+
65
+ // If this is the beginning of a [high, low] surrogate pair,
66
+ // add the next two characters, otherwise escape
67
+ if (code <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
68
+ result += char + str[++i];
69
+ } else {
70
+ result += unicode_encoder(code);
71
+ }
72
+ } else {
73
+ result += char;
74
+ }
75
+ }
76
+
77
+ return result;
78
+ }
79
+
1
80
  const absolute = /^([a-z]+:)?\/?\//;
2
81
  const scheme = /^[a-z]+:/;
3
82
 
@@ -37,4 +116,4 @@ function is_root_relative(path) {
37
116
  return path[0] === '/' && path[1] !== '/';
38
117
  }
39
118
 
40
- export { is_root_relative as i, resolve as r };
119
+ export { escape_json_string_in_html as a, escape_html_attr as e, is_root_relative as i, resolve as r };
package/dist/cli.js CHANGED
@@ -933,7 +933,7 @@ async function launch(port, https) {
933
933
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
934
934
  }
935
935
 
936
- const prog = sade('svelte-kit').version('1.0.0-next.237');
936
+ const prog = sade('svelte-kit').version('1.0.0-next.238');
937
937
 
938
938
  prog
939
939
  .command('dev')
@@ -1085,7 +1085,7 @@ async function check_port(port) {
1085
1085
  function welcome({ port, host, https, open, loose, allow, cwd }) {
1086
1086
  if (open) launch(port, https);
1087
1087
 
1088
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.237'}\n`));
1088
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.238'}\n`));
1089
1089
 
1090
1090
  const protocol = https ? 'https:' : 'http:';
1091
1091
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.237",
3
+ "version": "1.0.0-next.238",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -79,11 +79,13 @@
79
79
  "build": "rollup -c && node scripts/cp.js src/runtime/components assets/components",
80
80
  "dev": "rollup -cw",
81
81
  "lint": "eslint --ignore-path .gitignore --ignore-pattern \"src/packaging/test/**\" \"{src,test}/**/*.{ts,mjs,js,svelte}\" && npm run check-format",
82
- "check": "tsc && svelte-check --ignore \"src/packaging/test\"",
82
+ "check": "tsc && svelte-check --ignore test/prerendering,src/packaging/test",
83
83
  "format": "npm run check-format -- --write",
84
84
  "check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
85
- "test": "npm run test:unit && npm run test:packaging && npm run test:integration",
85
+ "test": "npm run test:unit && npm run test:packaging && npm run test:prerendering && npm run test:integration",
86
86
  "test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\" -i packaging",
87
+ "test:prerendering": "pnpm test:prerendering:basics",
88
+ "test:prerendering:basics": "cd test/prerendering/basics && pnpm test",
87
89
  "test:packaging": "uvu src/packaging \"(spec\\.js|test[\\\\/]index\\.js)\"",
88
90
  "test:integration": "pnpm test:integration:amp && pnpm test:integration:basics && pnpm test:integration:options && pnpm test:integration:options-2",
89
91
  "test:integration:amp": "cd test/apps/amp && pnpm test",