@sveltejs/kit 1.0.0-next.178 → 1.0.0-next.179

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.
@@ -412,7 +412,7 @@ function page_store(value) {
412
412
  function initial_fetch(resource, opts) {
413
413
  const url = typeof resource === 'string' ? resource : resource.url;
414
414
 
415
- let selector = `script[data-type="svelte-data"][data-url="${url}"]`;
415
+ let selector = `script[data-type="svelte-data"][data-url=${JSON.stringify(url)}]`;
416
416
 
417
417
  if (opts && typeof opts.body === 'string') {
418
418
  selector += `[data-body="${hash(opts.body)}"]`;
package/dist/cli.js CHANGED
@@ -817,7 +817,7 @@ async function launch(port, https) {
817
817
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
818
818
  }
819
819
 
820
- const prog = sade('svelte-kit').version('1.0.0-next.178');
820
+ const prog = sade('svelte-kit').version('1.0.0-next.179');
821
821
 
822
822
  prog
823
823
  .command('dev')
@@ -966,7 +966,7 @@ async function check_port(port) {
966
966
  function welcome({ port, host, https, open }) {
967
967
  if (open) launch(port, https);
968
968
 
969
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.178'}\n`));
969
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.179'}\n`));
970
970
 
971
971
  const protocol = https ? 'https:' : 'http:';
972
972
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
package/dist/ssr.js CHANGED
@@ -106,7 +106,7 @@ async function render_endpoint(request, route, match) {
106
106
  var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$';
107
107
  var unsafeChars = /[<>\b\f\n\r\t\0\u2028\u2029]/g;
108
108
  var reserved = /^(?:do|if|in|for|int|let|new|try|var|byte|case|char|else|enum|goto|long|this|void|with|await|break|catch|class|const|final|float|short|super|throw|while|yield|delete|double|export|import|native|return|switch|throws|typeof|boolean|default|extends|finally|package|private|abstract|continue|debugger|function|volatile|interface|protected|transient|implements|instanceof|synchronized)$/;
109
- var escaped$1 = {
109
+ var escaped = {
110
110
  '<': '\\u003C',
111
111
  '>': '\\u003E',
112
112
  '/': '\\u002F',
@@ -287,7 +287,7 @@ function getType(thing) {
287
287
  return Object.prototype.toString.call(thing).slice(8, -1);
288
288
  }
289
289
  function escapeUnsafeChar(c) {
290
- return escaped$1[c] || c;
290
+ return escaped[c] || c;
291
291
  }
292
292
  function escapeUnsafeChars(str) {
293
293
  return str.replace(unsafeChars, escapeUnsafeChar);
@@ -306,8 +306,8 @@ function stringifyString(str) {
306
306
  if (char === '"') {
307
307
  result += '\\"';
308
308
  }
309
- else if (char in escaped$1) {
310
- result += escaped$1[char];
309
+ else if (char in escaped) {
310
+ result += escaped[char];
311
311
  }
312
312
  else if (code >= 0xd800 && code <= 0xdfff) {
313
313
  var next = str.charCodeAt(i + 1);
@@ -399,6 +399,85 @@ function hash(value) {
399
399
  return (hash >>> 0).toString(36);
400
400
  }
401
401
 
402
+ /** @type {Record<string, string>} */
403
+ const escape_json_string_in_html_dict = {
404
+ '"': '\\"',
405
+ '<': '\\u003C',
406
+ '>': '\\u003E',
407
+ '/': '\\u002F',
408
+ '\\': '\\\\',
409
+ '\b': '\\b',
410
+ '\f': '\\f',
411
+ '\n': '\\n',
412
+ '\r': '\\r',
413
+ '\t': '\\t',
414
+ '\0': '\\0',
415
+ '\u2028': '\\u2028',
416
+ '\u2029': '\\u2029'
417
+ };
418
+
419
+ /** @param {string} str */
420
+ function escape_json_string_in_html(str) {
421
+ return escape(
422
+ str,
423
+ escape_json_string_in_html_dict,
424
+ (code) => `\\u${code.toString(16).toUpperCase()}`
425
+ );
426
+ }
427
+
428
+ /** @type {Record<string, string>} */
429
+ const escape_html_attr_dict = {
430
+ '<': '&lt;',
431
+ '>': '&gt;',
432
+ '"': '&quot;'
433
+ };
434
+
435
+ /**
436
+ * use for escaping string values to be used html attributes on the page
437
+ * e.g.
438
+ * <script data-url="here">
439
+ *
440
+ * @param {string} str
441
+ * @returns string escaped string
442
+ */
443
+ function escape_html_attr(str) {
444
+ return '"' + escape(str, escape_html_attr_dict, (code) => `&#${code};`) + '"';
445
+ }
446
+
447
+ /**
448
+ *
449
+ * @param str {string} string to escape
450
+ * @param dict {Record<string, string>} dictionary of character replacements
451
+ * @param unicode_encoder {function(number): string} encoder to use for high unicode characters
452
+ * @returns {string}
453
+ */
454
+ function escape(str, dict, unicode_encoder) {
455
+ let result = '';
456
+
457
+ for (let i = 0; i < str.length; i += 1) {
458
+ const char = str.charAt(i);
459
+ const code = char.charCodeAt(0);
460
+
461
+ if (char in dict) {
462
+ result += dict[char];
463
+ } else if (code >= 0xd800 && code <= 0xdfff) {
464
+ const next = str.charCodeAt(i + 1);
465
+
466
+ // If this is the beginning of a [high, low] surrogate pair,
467
+ // add the next two characters, otherwise escape
468
+ if (code <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
469
+ result += char + str[++i];
470
+ } else {
471
+ result += unicode_encoder(code);
472
+ }
473
+ } else {
474
+ result += char;
475
+ }
476
+ }
477
+
478
+ return result;
479
+ }
480
+
402
481
  const s$1 = JSON.stringify;
403
482
 
404
483
  // TODO rename this function/module
@@ -564,7 +643,9 @@ async function render_response({
564
643
 
565
644
  ${serialized_data
566
645
  .map(({ url, body, json }) => {
567
- let attributes = `type="application/json" data-type="svelte-data" data-url="${url}"`;
646
+ let attributes = `type="application/json" data-type="svelte-data" data-url=${escape_html_attr(
647
+ url
648
+ )}`;
568
649
  if (body) attributes += ` data-body="${hash(body)}"`;
569
650
 
570
651
  return `<script ${attributes}>${json}</script>`;
@@ -921,7 +1002,7 @@ async function load_node({
921
1002
  fetched.push({
922
1003
  url,
923
1004
  body: /** @type {string} */ (opts.body),
924
- json: `{"status":${response.status},"statusText":${s(response.statusText)},"headers":${s(headers)},"body":${escape(body)}}`
1005
+ json: `{"status":${response.status},"statusText":${s(response.statusText)},"headers":${s(headers)},"body":"${escape_json_string_in_html(body)}"}`
925
1006
  });
926
1007
  }
927
1008
 
@@ -985,53 +1066,6 @@ async function load_node({
985
1066
  };
986
1067
  }
987
1068
 
988
- /** @type {Record<string, string>} */
989
- const escaped = {
990
- '<': '\\u003C',
991
- '>': '\\u003E',
992
- '/': '\\u002F',
993
- '\\': '\\\\',
994
- '\b': '\\b',
995
- '\f': '\\f',
996
- '\n': '\\n',
997
- '\r': '\\r',
998
- '\t': '\\t',
999
- '\0': '\\0',
1000
- '\u2028': '\\u2028',
1001
- '\u2029': '\\u2029'
1002
- };
1003
-
1004
- /** @param {string} str */
1005
- function escape(str) {
1006
- let result = '"';
1007
-
1008
- for (let i = 0; i < str.length; i += 1) {
1009
- const char = str.charAt(i);
1010
- const code = char.charCodeAt(0);
1011
-
1012
- if (char === '"') {
1013
- result += '\\"';
1014
- } else if (char in escaped) {
1015
- result += escaped[char];
1016
- } else if (code >= 0xd800 && code <= 0xdfff) {
1017
- const next = str.charCodeAt(i + 1);
1018
-
1019
- // If this is the beginning of a [high, low] surrogate pair,
1020
- // add the next two characters, otherwise escape
1021
- if (code <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
1022
- result += char + str[++i];
1023
- } else {
1024
- result += `\\u${code.toString(16).toUpperCase()}`;
1025
- }
1026
- } else {
1027
- result += char;
1028
- }
1029
- }
1030
-
1031
- result += '"';
1032
- return result;
1033
- }
1034
-
1035
1069
  const absolute = /^([a-z]+:)?\/?\//;
1036
1070
 
1037
1071
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.178",
3
+ "version": "1.0.0-next.179",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",