Skip to content

Commit

Permalink
Merge pull request #9 from caridy/master
Browse files Browse the repository at this point in the history
bugfix: adding guarding for null values while trying to identify objects.
  • Loading branch information
caridy committed Oct 30, 2012
2 parents 293ebb4 + 41e9516 commit 253ff96
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function objectMerge(from, to) {
if (from.hasOwnProperty(key)) {
if (to.hasOwnProperty(key)) {
// Property in destination object set; update its value.
if (from[key].constructor === Object) {
if (from[key] && from[key].constructor === Object) {
to[key] = objectMerge(from[key], to[key]);
} else {
to[key] = from[key];
Expand Down Expand Up @@ -604,6 +604,7 @@ module.exports = {
* Processes an Object representing a YCB 2.0 Bundle as defined in the spec.
*
* @method read
* @param bundle {object}
* @param context {object}
* @param validate {boolean}
* @param debug {boolean}
Expand All @@ -623,6 +624,7 @@ module.exports = {
* Like read(), but doesn't merge the found sections.
*
* @method readNoMerge
* @param bundle {object}
* @param context {object}
* @param validate {boolean}
* @param debug {boolean}
Expand Down
20 changes: 20 additions & 0 deletions tests/fixtures/simple-4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"settings": ["master"],
"foo": null,
"bar": 0,
"baz": false,
"oof": 4,
"rab": 5,
"zab": 6
},
{
"settings": ["lang:fr"],
"foo": 1,
"bar": 2,
"baz": 3,
"oof": null,
"rab": 0,
"zab": false
}
]
22 changes: 20 additions & 2 deletions tests/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ suite.add(new Y.Test.Case({
'lang': 'fr_FR'
};
config = libycb.read(bundle, context);

A.areSame('YRB_YAHOO', config.title_key);
A.areSame('yahoo_FR.png', config.logo);
A.areSame('http://gb.yahoo.com', config.links.home);
Expand Down Expand Up @@ -439,8 +438,27 @@ suite.add(new Y.Test.Case({

A.areNotSame(obj.list, copy.list);
AA.itemsAreEqual(obj.list, copy.list);
}
},

'test objectMerge': function () {
var bundle,
ycb;

bundle = readFixtureFile('dimensions.json')
.concat(readFixtureFile('simple-4.json'));
ycb = new libycb.Ycb(bundle);
var config = ycb.read({
'lang': 'fr'
});
OA.areEqual({
foo: 1,
bar: 2,
baz: 3,
oof: null,
rab: 0,
zab: false
}, config);
}

}));

Expand Down

0 comments on commit 253ff96

Please sign in to comment.