From 6f15eb9f4c6d53ec2079006dd101a09a6fcd7bd4 Mon Sep 17 00:00:00 2001 From: Tymoteusz Czech <2625371+Tymek@users.noreply.github.com> Date: Fri, 7 Jul 2023 17:40:37 +0200 Subject: [PATCH] fix: correct escaping of ui flags for plausible (#3907) ## About the changes Stringified JSON still needs to be escaped before being placed in an HTML attribute. --- .../component/providers/PlausibleProvider/PlausibleProvider.tsx | 2 +- src/lib/util/load-index-html.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/component/providers/PlausibleProvider/PlausibleProvider.tsx b/frontend/src/component/providers/PlausibleProvider/PlausibleProvider.tsx index 08420407df..3a781d1713 100644 --- a/frontend/src/component/providers/PlausibleProvider/PlausibleProvider.tsx +++ b/frontend/src/component/providers/PlausibleProvider/PlausibleProvider.tsx @@ -20,7 +20,7 @@ export const PlausibleProvider: FC = ({ children }) => { 'meta[name="uiFlags"]' ) as HTMLMetaElement )?.content || '{}'; - return JSON.parse(uiFlagsStr); + return JSON.parse(decodeURI(uiFlagsStr)); } catch (e) { return {}; } diff --git a/src/lib/util/load-index-html.ts b/src/lib/util/load-index-html.ts index 865162af0e..a163d0b90d 100644 --- a/src/lib/util/load-index-html.ts +++ b/src/lib/util/load-index-html.ts @@ -9,7 +9,7 @@ export async function loadIndexHTML( publicFolder: string, ): Promise { const { cdnPrefix, baseUriPath = '' } = config.server; - const uiFlags = JSON.stringify(config.ui.flags); + const uiFlags = encodeURI(JSON.stringify(config.ui.flags || '{}')); let indexHTML: string; if (cdnPrefix) {