mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
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,7 +136,9 @@ const onMouseLeave = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const receiveMessage = ({ data }: MessageEvent) => {
|
const receiveMessage = ({ data }: MessageEvent) => {
|
||||||
if (data?.includes('"command"')) {
|
if (!data?.includes?.('"command"')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const json = JSON.parse(data);
|
const json = JSON.parse(data);
|
||||||
if (json.command === 'n8nReady') {
|
if (json.command === 'n8nReady') {
|
||||||
@@ -151,7 +153,6 @@ const receiveMessage = ({ data }: MessageEvent) => {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
const onDocumentScroll = () => {
|
const onDocumentScroll = () => {
|
||||||
if (insideIframe.value) {
|
if (insideIframe.value) {
|
||||||
|
|||||||
@@ -247,4 +247,18 @@ describe('WorkflowPreview', () => {
|
|||||||
expect(emitted()).toEqual({});
|
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({});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4312,7 +4312,9 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
async onPostMessageReceived(message: MessageEvent) {
|
async onPostMessageReceived(message: MessageEvent) {
|
||||||
if (message?.data?.includes('"command"')) {
|
if (!message?.data?.includes?.('"command"')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const json = JSON.parse(message.data);
|
const json = JSON.parse(message.data);
|
||||||
if (json && json.command === 'openWorkflow') {
|
if (json && json.command === 'openWorkflow') {
|
||||||
@@ -4363,7 +4365,6 @@ export default defineComponent({
|
|||||||
this.workflowsStore.activeWorkflowExecution = json.execution;
|
this.workflowsStore.activeWorkflowExecution = json.execution;
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
|
||||||
},
|
},
|
||||||
async onImportWorkflowDataEvent(data: IDataObject) {
|
async onImportWorkflowDataEvent(data: IDataObject) {
|
||||||
await this.importWorkflowData(data.data as IWorkflowDataUpdate, 'file');
|
await this.importWorkflowData(data.data as IWorkflowDataUpdate, 'file');
|
||||||
|
|||||||
Reference in New Issue
Block a user