Skip to content

Commit

Permalink
fix: Update global variable handling in views to use decodeURICompone…
Browse files Browse the repository at this point in the history
…nt (#4383)

Signed-off-by: ya zhou <[email protected]>
  • Loading branch information
yazhouio authored Dec 24, 2024
1 parent 74db818 commit 91b30dd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 31 deletions.
62 changes: 34 additions & 28 deletions server/controllers/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ const renderIndex = async (ctx, params) => {
extStyles,
hostname: ctx.hostname,
importMap: JSON.stringify(importMap),
globals: JSON.stringify({
config: clientConfig,
manifest,
localeManifest,
theme,
defaultTheme,
useDefaultTheme,
...params,
}),
globals: encodeURIComponent(
JSON.stringify({
config: clientConfig,
manifest,
localeManifest,
theme,
defaultTheme,
useDefaultTheme,
...params,
}),
)
});
};

Expand All @@ -82,16 +84,18 @@ const renderV3Index = async (ctx, params) => {
isDev: global.MODE_DEV,
title: clientConfig.title,
hostname: ctx.hostname,
globals: JSON.stringify({
config: clientConfig,
localeManifest,
globals: encodeURIComponent(
JSON.stringify({
config: clientConfig,
localeManifest,

theme,
defaultTheme,
useDefaultTheme,
theme,
defaultTheme,
useDefaultTheme,

...params,
}),
...params,
}),
)
});
};

Expand Down Expand Up @@ -164,17 +168,19 @@ const renderTerminal = async ctx => {
favicon,
hostname: ctx.hostname,
importMap: JSON.stringify(importMap),
globals: JSON.stringify({
config: clientConfig,
manifest,
localeManifest,
user,
ksConfig,
runtime,
theme,
defaultTheme,
useDefaultTheme,
}),
globals: encodeURIComponent(
JSON.stringify({
config: clientConfig,
manifest,
localeManifest,
user,
ksConfig,
runtime,
theme,
defaultTheme,
useDefaultTheme,
}),
)
});
} catch (err) {
await renderViewErr(ctx, err);
Expand Down
2 changes: 1 addition & 1 deletion server/views/consolev3.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<body>
<div id="root"></div>
<script type="text/javascript">
window.globals = JSON.parse(`<%- globals %>`);
window.globals = JSON.parse(decodeURIComponent(`<%- globals %>`));
</script>
<% if (manifest && manifest.js && manifest.js.length > 0) { %> <%
manifest.js.forEach(function(item){ %>
Expand Down
2 changes: 1 addition & 1 deletion server/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{ "imports": <%- importMap %> }
</script>
<script type="text/javascript">
window.globals = JSON.parse(`<%- globals %>`);
window.globals = JSON.parse(decodeURIComponent(`<%- globals %>`));
</script>
<% if (isDev) { %> <%- include('./components/dev_scripts.html') %> <% } else { %> <%-
include('./components/prod_scripts.html') %> <% } %>
Expand Down
2 changes: 1 addition & 1 deletion server/views/terminal.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{ "imports": <%- importMap %> }
</script>
<script type="text/javascript">
window.globals = JSON.parse(`<%- globals %>`);
window.globals = JSON.parse(decodeURIComponent(`<%- globals %>`));
</script>
<% if (isDev) { %>
<script type="text/javascript" src="<%= bundlePrefix %>/runtime.js"></script>
Expand Down

0 comments on commit 91b30dd

Please sign in to comment.