Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
fix: resolve falsy values
Browse files Browse the repository at this point in the history
Legitimate JSON values in scope of the node were not being resolved properly because of a falsy value check. This tightens the check to allow falsy, in scope, values to be resolved.

License: MIT
Signed-off-by: Alan Shaw <[email protected]>
  • Loading branch information
alanshaw authored and vmx committed Sep 11, 2018
1 parent 815ed2f commit 0a49705
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ exports.resolve = (binaryBlob, path, callback) => {
const parts = path.split('/')
const val = traverse(node).get(parts)

if (val) {
if (val !== undefined) {
return callback(null, {
value: val,
remainderPath: ''
Expand Down
22 changes: 22 additions & 0 deletions test/resolver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ chai.use(dirtyChai)

const waterfall = require('async/waterfall')
const parallel = require('async/parallel')
const each = require('async/each')
const CID = require('cids')

const dagCBOR = require('../src')
Expand Down Expand Up @@ -132,6 +133,27 @@ describe('IPLD format resolver (local)', () => {
})
})

it('should resolve falsy values for path within scope', (done) => {
const node = {
nu11: null,
f4lse: false,
empty: '',
zero: 0
}

dagCBOR.util.serialize(node, (err, nodeBlob) => {
expect(err).to.not.exist()

each(Object.keys(node), (key, cb) => {
resolver.resolve(nodeBlob, key, (err, result) => {
expect(err).to.not.exist()
expect(result.value).to.equal(node[key])
cb()
})
}, done)
})
})

it('path out of scope', (done) => {
resolver.resolve(nodeBlob, 'someLink/a/b/c', (err, result) => {
expect(err).to.not.exist()
Expand Down

0 comments on commit 0a49705

Please sign in to comment.