Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 3066ba1

Browse files
committed
fix: utils.scopeData should not copy $value if public properties are found
1 parent fd4409f commit 3066ba1

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/utils.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,15 @@
313313
$id: dataOrRec.$id,
314314
$priority: dataOrRec.$priority
315315
};
316-
if( dataOrRec.hasOwnProperty('$value') ) {
316+
var hasPublicProp = false;
317+
utils.each(dataOrRec, function(v,k) {
318+
hasPublicProp = true;
319+
data[k] = utils.deepCopy(v);
320+
});
321+
if(!hasPublicProp && dataOrRec.hasOwnProperty('$value')){
317322
data.$value = dataOrRec.$value;
318323
}
319-
return utils.extendData(data, dataOrRec);
324+
return data;
320325
},
321326

322327
updateRec: function(rec, snap) {

tests/unit/utils.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,23 @@ describe('$firebaseUtils', function () {
110110
});
111111
});
112112

113+
describe('#scopeData',function(){
114+
it('$value, $priority, and $value are only private properties that get copied',function(){
115+
var data = {$id:'foo',$priority:'bar',$value:null,$private1:'baz',$private2:'foo'};
116+
expect($utils.scopeData(data)).toEqual({$id:'foo',$priority:'bar',$value:null});
117+
});
118+
119+
it('all public properties will be copied',function(){
120+
var data = {$id:'foo',$priority:'bar',public1:'baz',public2:'test'};
121+
expect($utils.scopeData(data)).toEqual({$id:'foo',$priority:'bar',public1:'baz',public2:'test'});
122+
});
123+
124+
it('$value will not be copied if public properties are present',function(){
125+
var data = {$id:'foo',$priority:'bar',$value:'noCopy',public1:'baz',public2:'test'};
126+
expect($utils.scopeData(data)).toEqual({$id:'foo',$priority:'bar',public1:'baz',public2:'test'});
127+
});
128+
});
129+
113130
describe('#applyDefaults', function() {
114131
it('should return rec', function() {
115132
var rec = {foo: 'bar'};

0 commit comments

Comments
 (0)