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

Commit

Permalink
fix: Fix false positives in isLink and update test (#51)
Browse files Browse the repository at this point in the history
* Fix false positives in isLink and update test

* isLink - test both blank and non-blank non-CID cases
  • Loading branch information
AdamStone authored and daviddias committed Jan 7, 2018
1 parent ea7eea2 commit 73b21c7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/resolver.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

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

const util = require('./util')

Expand Down Expand Up @@ -117,9 +118,17 @@ exports.isLink = (block, path, callback) => {
}

if (typeof result.value === 'object' && result.value['/']) {
callback(null, result.value)
} else {
callback(null, false)
let valid
try {
valid = CID.isCID(new CID(result.value['/']))
} catch (err) {
valid = false
}
if (valid) {
return callback(null, result.value)
}
}

callback(null, false)
})
}
8 changes: 7 additions & 1 deletion test/resolver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,16 @@ describe('IPLD Format resolver (local)', () => {
})

it('resolver.isLink for non valid CID', (done) => {
// blank value case
resolver.isLink(dataLinksNodeBlock, 'Links/0/Name', (err, link) => {
expect(err).to.not.exist()
expect(link).to.equal(false)
done()
// non-blank value case
resolver.isLink(dataLinksNodeBlock, 'Links/0/Tsize', (err, link) => {
expect(err).to.not.exist()
expect(link).to.equal(false)
done()
})
})
})
})

0 comments on commit 73b21c7

Please sign in to comment.