Skip to content

Avoid direct mutation on objects that are passed into a function #6

@dzwillia

Description

@dzwillia

In the following code, when calling _.get(json, 'params', json), the params node is no longer found since we've now flattened the task JSON, however the third parameter json is the object that is passed into the toCode function and so the delete params['op'] call is actually mutating the object that was passed into this function, which actually propagates all the way back to an object that was passed into the JS SDK from outside code.

This is happening in the following places (that I could see):

Connect

connect.toCode = function(json, Flexio) {
var params = _.get(json, 'params', json)
delete params['op']
return 'connect(' + JSON.stringify(params) + ')'
}

Email

email.toCode = function(json, Flexio) {
var params = _.get(json, 'params', json)
delete params['op']
return 'email(' + JSON.stringify(params, null, 2) + ')'
}

Transform

transform.toCode = function(json, Flexio) {
var params = _.get(json, 'params', json)
delete params['op']
if (!_.has(params,'columns') && _.has(params, 'operations') && Array.isArray(params.operations) && params.operations.length == 1) {
return "transform(" + JSON.stringify(params.operations[0]) + ")"
} else {
return "transform(" + JSON.stringify(params) + ")"
}
}

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions