fix(editor): Return early in ws message handler if no 'command' keyword is found (#7946)
## Summary Avoid processing websocket messages not n8n sent (filter on 'command' keyword)
This commit is contained in:
@@ -136,21 +136,22 @@ const onMouseLeave = () => {
|
||||
};
|
||||
|
||||
const receiveMessage = ({ data }: MessageEvent) => {
|
||||
if (data?.includes('"command"')) {
|
||||
try {
|
||||
const json = JSON.parse(data);
|
||||
if (json.command === 'n8nReady') {
|
||||
ready.value = true;
|
||||
} else if (json.command === 'openNDV') {
|
||||
nodeViewDetailsOpened.value = true;
|
||||
} else if (json.command === 'closeNDV') {
|
||||
nodeViewDetailsOpened.value = false;
|
||||
} else if (json.command === 'error') {
|
||||
emit('close');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
if (!data?.includes?.('"command"')) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const json = JSON.parse(data);
|
||||
if (json.command === 'n8nReady') {
|
||||
ready.value = true;
|
||||
} else if (json.command === 'openNDV') {
|
||||
nodeViewDetailsOpened.value = true;
|
||||
} else if (json.command === 'closeNDV') {
|
||||
nodeViewDetailsOpened.value = false;
|
||||
} else if (json.command === 'error') {
|
||||
emit('close');
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
};
|
||||
const onDocumentScroll = () => {
|
||||
|
||||
@@ -247,4 +247,18 @@ describe('WorkflowPreview', () => {
|
||||
expect(emitted()).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
it('should not do anything if no "command" is sent in the message and the `includes` method cannot be applied to the data', async () => {
|
||||
const { emitted } = renderComponent({
|
||||
pinia,
|
||||
props: {},
|
||||
});
|
||||
|
||||
window.postMessage(null, '*');
|
||||
|
||||
await waitFor(() => {
|
||||
expect(console.error).not.toHaveBeenCalled();
|
||||
expect(emitted()).toEqual({});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user