From 8e0c73816d10498a8b21fad09e86e54b3d43af2c Mon Sep 17 00:00:00 2001 From: Zino Hofmann Date: Mon, 20 Nov 2023 09:18:59 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20correctly=20access=20PUBL?= =?UTF-8?q?IC=5FENV=5FKEY=20on=20window?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/script/env-script.spec.tsx | 2 +- src/script/env-script.tsx | 2 +- src/script/public-env-script.spec.tsx | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/script/env-script.spec.tsx b/src/script/env-script.spec.tsx index f1681dbd..9053e67c 100644 --- a/src/script/env-script.spec.tsx +++ b/src/script/env-script.spec.tsx @@ -27,7 +27,7 @@ describe('EnvProvider', () => { const { getByTestId } = render(); expect(getByTestId('env-script').textContent).toBe( - `window[__ENV] = ${JSON.stringify(env)}`, + `window['__ENV'] = ${JSON.stringify(env)}`, ); }); diff --git a/src/script/env-script.tsx b/src/script/env-script.tsx index ef9fddff..cddeda91 100644 --- a/src/script/env-script.tsx +++ b/src/script/env-script.tsx @@ -40,7 +40,7 @@ export const EnvScript: FC = ({ env, nonce }) => { data-testid="env-script" nonce={nonceString} dangerouslySetInnerHTML={{ - __html: `window[${PUBLIC_ENV_KEY}] = ${JSON.stringify(env)}`, + __html: `window['${PUBLIC_ENV_KEY}'] = ${JSON.stringify(env)}`, }} /> ); diff --git a/src/script/public-env-script.spec.tsx b/src/script/public-env-script.spec.tsx index 3a78a7f9..7e8446f1 100644 --- a/src/script/public-env-script.spec.tsx +++ b/src/script/public-env-script.spec.tsx @@ -29,7 +29,7 @@ describe('PublicEnvProvider', () => { const { getByTestId } = render(); expect(getByTestId('env-script').textContent).toBe( - `window[__ENV] = {"NEXT_PUBLIC_FOO":"foo-value"}`, + `window['__ENV'] = {"NEXT_PUBLIC_FOO":"foo-value"}`, ); }); @@ -40,7 +40,7 @@ describe('PublicEnvProvider', () => { const { getByTestId } = render(); - expect(getByTestId('env-script').textContent).toBe(`window[__ENV] = {}`); + expect(getByTestId('env-script').textContent).toBe(`window['__ENV'] = {}`); }); it('should only set public env in the script', () => { @@ -52,7 +52,7 @@ describe('PublicEnvProvider', () => { const { getByTestId } = render(); expect(getByTestId('env-script').textContent).toBe( - `window[__ENV] = {"NEXT_PUBLIC_FOO":"foo-value"}`, + `window['__ENV'] = {"NEXT_PUBLIC_FOO":"foo-value"}`, ); });