fix: clone logged object to prevent mutation to it (#17756)

This commit is contained in:
arunvjn 2022-10-26 10:07:53 +05:30 committed by GitHub
parent f455dae7a8
commit 368cafdf78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 8 deletions

View File

@ -373,11 +373,32 @@ describe("Debugger logs", function() {
debuggerHelper.Assert_Consecutive_Console_Log_Count(5);
});
// it("Api headers need to be shown as headers in logs", function() {
// // TODO
// });
// it("Api body needs to be shown as JSON when possible", function() {
// // TODO
// });
it("18. Console log should not mutate the passed object", function() {
ee.NavigateToSwitcher("explorer");
jsEditor.CreateJSObject(
`export default {
myFun1: () => {
let data = [];
console.log("start:", data);
for(let i=0; i<5; i++)
data.push(i);
console.log("end:", JSON.stringify(data));
return data;
},
myFun2: () => {
return 1;
}
}`,
{
paste: true,
completeReplace: true,
toRun: true,
shouldCreateNewJSObj: true,
prettify: false,
},
);
agHelper.GetNClick(jsEditor._logsTab);
debuggerHelper.DoesConsoleLogExist("start: []");
debuggerHelper.DoesConsoleLogExist("end: [0,1,2,3,4]");
});
});

View File

@ -1,6 +1,7 @@
import { uuid4 } from "@sentry/utils";
import { EventType } from "constants/AppsmithActionConstants/ActionConstants";
import { LogObject, Methods, Severity } from "entities/AppsmithConsole";
import { klona } from "klona/lite";
import moment from "moment";
import { TriggerMeta } from "sagas/ActionExecution/ActionExecutionSagas";
import { _internalClearTimeout, _internalSetTimeout } from "./TimeoutOverride";
@ -131,7 +132,7 @@ class UserLog {
return {
method,
id,
data: output,
data: klona(output),
timestamp,
severity,
};