Skip to content

Commit 1df0eb5

Browse files
fix(store-devtools): replace direct with indirect eval (#4216)
Closes #4213
1 parent fa45d92 commit 1df0eb5

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

modules/store-devtools/spec/extension.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ReduxDevtoolsExtensionConnection,
55
ReduxDevtoolsExtensionConfig,
66
REDUX_DEVTOOLS_EXTENSION,
7+
ExtensionActionTypes,
78
} from './../src/extension';
89
import { Action } from '@ngrx/store';
910

@@ -182,6 +183,36 @@ describe('DevtoolsExtension', () => {
182183
);
183184
});
184185

186+
for (const { payload, name } of [
187+
{
188+
payload: "{type: '[Books] Rent', id: 5, customerId: 12}",
189+
name: 'evaluates payload because of string',
190+
},
191+
{
192+
payload: { type: '[Books] Rent', id: 5, customerId: 12 },
193+
name: 'passes payload through if not of type string',
194+
},
195+
]) {
196+
it(`should handle an unlifted action (dispatched by DevTools) - ${name}`, () => {
197+
const { devtoolsExtension, extensionConnection } = testSetup({
198+
config: createConfig({}),
199+
});
200+
let unwrappedAction: Action | undefined = undefined;
201+
devtoolsExtension.actions$.subscribe((action) => {
202+
return (unwrappedAction = action);
203+
});
204+
205+
const [callback] = extensionConnection.subscribe.calls.mostRecent().args;
206+
callback({ type: ExtensionActionTypes.START });
207+
callback({ type: ExtensionActionTypes.ACTION, payload });
208+
expect(unwrappedAction).toEqual({
209+
type: '[Books] Rent',
210+
id: 5,
211+
customerId: 12,
212+
});
213+
});
214+
}
215+
185216
describe('notify', () => {
186217
it('should send notification with default options', () => {
187218
const { devtoolsExtension, reduxDevtoolsExtension } = testSetup({

modules/store-devtools/src/extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ export class DevtoolsExtension {
247247
}
248248

249249
private unwrapAction(action: Action) {
250-
return typeof action === 'string' ? eval(`(${action})`) : action;
250+
// indirect eval according to https://esbuild.github.io/content-types/#direct-eval
251+
return typeof action === 'string' ? (0, eval)(`(${action})`) : action;
251252
}
252253

253254
private getExtensionConfig(config: StoreDevtoolsConfig) {

0 commit comments

Comments
 (0)