Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: typeof bug when passing timeout to dag.get (#3035)
Browse files Browse the repository at this point in the history
Passing `options` without a `path` to dag.get will throw an error.
```
ipfs.dag.get(cidPath, { timeout: 2000 })

TypeError: Cannot read property 'timeout' of null
```

Cause by the lovely JS issue of `typeof null === 'object'`.

Co-authored-by: Kia Rahimian <kia@tintmail.com>
  • Loading branch information
achingbrain and mistakia authored May 14, 2020
1 parent 3e4a716 commit 026a542
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/interface-ipfs-core/src/dag/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ module.exports = (common, options) => {
expect(result.value.equals(cidPb)).to.be.true()
})

it('should get with options and no path', async function () {
const result = await ipfs.dag.get(cidCbor, { localResolve: true })
expect(result.value).to.deep.equal(nodeCbor)
})

it('should get a node added as CIDv0 with a CIDv1', async () => {
const input = Buffer.from(`TEST${Math.random()}`)

Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-http-client/src/dag/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = configure((api, options) => {
const dagResolve = require('./resolve')(options)

return async (cid, path, options = {}) => {
if (typeof path === 'object') {
if (path && typeof path === 'object') {
options = path
path = null
}
Expand Down

0 comments on commit 026a542

Please sign in to comment.