Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit eff36923
authored
Jul 01, 2015
by
Daniel Friesen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #4040, do not call .clone method on plain objects or arrays.
1 parent
eaf197fa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
1 deletions
lib/utils.js
test/integration/utils.test.js
lib/utils.js
View file @
eff3692
...
@@ -96,7 +96,7 @@ var Utils = module.exports = {
...
@@ -96,7 +96,7 @@ var Utils = module.exports = {
cloneDeep
:
function
(
obj
,
fn
)
{
cloneDeep
:
function
(
obj
,
fn
)
{
return
lodash
.
cloneDeep
(
obj
,
function
(
elem
)
{
return
lodash
.
cloneDeep
(
obj
,
function
(
elem
)
{
// Preserve special data-types like `fn` across clones. _.get() is used for checking up the prototype chain
// Preserve special data-types like `fn` across clones. _.get() is used for checking up the prototype chain
if
(
elem
&&
typeof
elem
.
clone
===
'function'
)
{
return
elem
.
clone
();
}
if
(
elem
&&
!
Array
.
isArray
(
elem
)
&&
!
lodash
.
isPlainObject
(
elem
)
&&
typeof
elem
.
clone
===
'function'
)
{
return
elem
.
clone
();
}
// Unfortunately, lodash.cloneDeep doesn't preserve Buffer.isBuffer, which we have to rely on for binary data
// Unfortunately, lodash.cloneDeep doesn't preserve Buffer.isBuffer, which we have to rely on for binary data
if
(
Buffer
.
isBuffer
(
elem
))
{
return
elem
;
}
if
(
Buffer
.
isBuffer
(
elem
))
{
return
elem
;
}
...
...
test/integration/utils.test.js
View file @
eff3692
...
@@ -109,6 +109,43 @@ describe(Support.getTestDialectTeaser('Utils'), function() {
...
@@ -109,6 +109,43 @@ describe(Support.getTestDialectTeaser('Utils'), function() {
});
});
});
});
describe
(
'cloneDeep'
,
function
()
{
it
(
'should clone objects'
,
function
()
{
var
obj
=
{
foo
:
1
},
clone
=
Utils
.
cloneDeep
(
obj
);
expect
(
obj
).
to
.
not
.
equal
(
clone
);
});
it
(
'should clone nested objects'
,
function
()
{
var
obj
=
{
foo
:
{
bar
:
1
}},
clone
=
Utils
.
cloneDeep
(
obj
);
expect
(
obj
.
foo
).
to
.
not
.
equal
(
clone
.
foo
);
});
it
(
'should not call clone methods on plain objects'
,
function
()
{
expect
(
function
()
{
Utils
.
cloneDeep
({
clone
:
function
()
{
throw
new
Error
(
'clone method called'
);
}
});
}).
to
.
not
.
throw
();
});
it
(
'should not call clone methods on arrays'
,
function
()
{
expect
(
function
()
{
var
arr
=
[];
arr
.
clone
=
function
()
{
throw
new
Error
(
'clone method called'
);
};
Utils
.
cloneDeep
(
arr
);
}).
to
.
not
.
throw
();
});
});
describe
(
'validateParameter'
,
function
()
{
describe
(
'validateParameter'
,
function
()
{
describe
(
'method signature'
,
function
()
{
describe
(
'method signature'
,
function
()
{
it
(
'throws an error if the value is not defined'
,
function
()
{
it
(
'throws an error if the value is not defined'
,
function
()
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment