File tree 2 files changed +21
-0
lines changed
2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 23
23
24
24
var arrify = require ( 'arrify' ) ;
25
25
var createErrorClass = require ( 'create-error-class' ) ;
26
+ var extend = require ( 'extend' ) ;
26
27
var is = require ( 'is' ) ;
27
28
28
29
var entity = module . exports ;
@@ -285,6 +286,8 @@ function encodeValue(value) {
285
286
286
287
if ( is . object ( value ) ) {
287
288
if ( ! is . empty ( value ) ) {
289
+ value = extend ( true , { } , value ) ;
290
+
288
291
for ( var prop in value ) {
289
292
if ( value . hasOwnProperty ( prop ) ) {
290
293
value [ prop ] = entity . encodeValue ( value [ prop ] ) ;
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ var deepStrictEqual = require('deep-strict-equal');
21
21
assert . deepStrictEqual = assert . deepStrictEqual || function ( ) {
22
22
return assert ( deepStrictEqual . apply ( this , arguments ) ) ;
23
23
} ;
24
+ var extend = require ( 'extend' ) ;
24
25
25
26
var Datastore = require ( '../' ) ;
26
27
@@ -430,6 +431,23 @@ describe('entity', function() {
430
431
assert . deepEqual ( entity . encodeValue ( value ) , expectedValueProto ) ;
431
432
} ) ;
432
433
434
+ it ( 'should clone an object' , function ( ) {
435
+ var value = {
436
+ a : {
437
+ b : {
438
+ obj : true
439
+ }
440
+ }
441
+ } ;
442
+
443
+ var originalValue = extend ( true , { } , value ) ;
444
+
445
+ var encodedValue = entity . encodeValue ( value ) ;
446
+
447
+ assert . deepEqual ( value , originalValue ) ;
448
+ assert . notStrictEqual ( value , encodedValue ) ;
449
+ } ) ;
450
+
433
451
it ( 'should encode an empty object' , function ( ) {
434
452
var value = { } ;
435
453
You can’t perform that action at this time.
0 commit comments