Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing bug when using null values #9

Merged
merged 1 commit into from
Oct 30, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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