dominictarr / rc

The non-configurable configuration loader for lazy people.
Other
1.02k stars 97 forks source link

primitive key may get error #69

Open honchy opened 8 years ago

honchy commented 8 years ago

in folder lib utils.js

    if (cursor[_subkey] === undefined) {
        console.log('undefined ' + cursor);
        cursor[_subkey] = {}
    }

where cursor[_subkey] is a primitive value ,like boolean , cursor[_subkey] = {} may get undefined value.

so code below

    // Increment cursor used to track the object at the current depth
    cursor = cursor[_subkey]

will still got an undefind value.

I just don't much about rc, I found this problem when I install another project.

tks

honchy commented 8 years ago

I try to fix this like code blow

    // Build sub-object if nothing already exists at the keypath
    if (cursor[_subkey] === undefined) {
        cursor = {}
    } else {
        // Increment cursor used to track the object at the current depth
        cursor = cursor[_subkey]
    }

And It sems works.

legodude17 commented 8 years ago

Above that there is this line:

if (!_subkey || typeof cursor !== 'object')
          return

That should make it so that now primitive keys actually get to that point.