Skip to content

Commit 5bfeb05

Browse files
committed
refactor: improve JSON escaping in escapeJsonForScript and enhance isFullscreen parsing logic
1 parent 351d94a commit 5bfeb05

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

apps/api/src/app/utils/canvas.utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ import { join } from 'node:path';
1010
* that would break the enclosing JS string literal.
1111
*/
1212
export function escapeJsonForScript(json: string): string {
13-
return json.replace(/</g, '\\u003c').replace(/>/g, '\\u003e').replace(/\//g, '\\u002f').replace(/'/g, '\\u0027');
13+
return json
14+
.replace(/</g, '\\u003c')
15+
.replace(/>/g, '\\u003e')
16+
.replace(/\//g, '\\u002f')
17+
.replace(/'/g, '\\u0027')
18+
.replace(/\u2028/g, '\\u2028')
19+
.replace(/\u2029/g, '\\u2029');
1420
}
1521

1622
/**

apps/jetstream-canvas/src/app/app.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import './core/monaco-loader';
1313
const Sfdc = window.Sfdc;
1414

1515
// The fullscreen VF page passes { isFullScreen: true } via the apex:canvasApp parameters attribute
16-
const isFullscreen = z.coerce.boolean().default(true).parse(sr.context?.environment?.parameters?.isFullScreen);
16+
const isFullscreen = z
17+
.preprocess((val) => (val === undefined ? true : val), z.coerce.boolean())
18+
.parse(sr.context?.environment?.parameters?.isFullScreen);
1719

1820
export const App = () => {
1921
return (

apps/jetstream-canvas/src/controllers/route.utils.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@ export function createRoute<TParamsSchema extends z.ZodTypeAny, TBodySchema exte
6666
if (req.request.method !== 'GET' && !skipBodyParsing) {
6767
const contentType = req.request.headers.get('content-type') ?? '';
6868
if (contentType.startsWith('application/json')) {
69-
try {
70-
parsedBody = await req.request.json();
71-
} catch {
72-
// headers may not have been correct, just ignore and continue
73-
}
69+
parsedBody = await req.request.json();
7470
} else if (contentType.startsWith('application/zip')) {
7571
parsedBody = await req.request.arrayBuffer();
7672
} else {
@@ -81,7 +77,7 @@ export function createRoute<TParamsSchema extends z.ZodTypeAny, TBodySchema exte
8177
try {
8278
const data = {
8379
params: params ? params.parse(req.params) : undefined,
84-
body: body && parsedBody !== undefined ? body.parse(parsedBody) : undefined,
80+
body: body ? body.parse(parsedBody) : undefined,
8581
query: query ? query.parse(queryParams) : undefined,
8682
jetstreamConn: req.jetstreamConn,
8783
targetJetstreamConn: req.targetJetstreamConn,

0 commit comments

Comments
 (0)