Skip to content

Commit a3c2316

Browse files
committed
using escape_json_string_in_html
1 parent 886ad46 commit a3c2316

File tree

1 file changed

+3
-19
lines changed
  • packages/kit/src/runtime/server/page

1 file changed

+3
-19
lines changed

packages/kit/src/runtime/server/page/render.js

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import devalue from 'devalue';
22
import { readable, writable } from 'svelte/store';
33
import { coalesce_to_error } from '../../../utils/error.js';
44
import { hash } from '../../hash.js';
5-
import { escape_html_attr } from '../../../utils/escape.js';
5+
import { escape_html_attr, escape_json_string_in_html } from '../../../utils/escape.js';
66
import { s } from '../../../utils/misc.js';
77
import { create_prerendering_url_proxy } from './utils.js';
88
import { Csp, csp_ready } from './csp.js';
@@ -260,24 +260,8 @@ export async function render_response({
260260
.join('\n\t');
261261

262262
if (shadow_props) {
263-
// adapted from https://github.com/vercel/next.js/blob/694407450638b037673c6d714bfe4126aeded740/packages/next/server/htmlescape.ts
264-
// based on https://github.com/zertosh/htmlescape
265-
// License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE
266-
/**
267-
* @type { Record<string, string> }
268-
*/
269-
const escape_lookup = {
270-
'&': '\\u0026',
271-
'>': '\\u003e',
272-
'<': '\\u003c',
273-
'\u2028': '\\u2028',
274-
'\u2029': '\\u2029'
275-
};
276-
const escaped_shadow_props = s(shadow_props).replace(
277-
/[&><\u2028\u2029]/g,
278-
(match) => escape_lookup[match]
279-
);
280-
body += `<script type="application/json" data-type="svelte-props">${escaped_shadow_props}</script>`;
263+
// prettier-ignore
264+
body += `<script type="application/json" data-type="svelte-props">${escape_json_string_in_html(s(shadow_props))}</script>`;
281265
}
282266
}
283267

0 commit comments

Comments
 (0)