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

Commit

Permalink
fix: ensure empty link names are preserved
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Nov 24, 2016
1 parent 72c7223 commit ad11b7a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/dag-node/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ function create (data, dagLinks, hashAlg, callback) {
}

return new DAGLink(
l.name || l.Name,
l.size || l.Size,
l.hash || l.Hash || l.multihash)
l.name != null ? l.name : l.Name,
l.size != null ? l.size : l.Size,
l.hash || l.Hash || l.multihash
)
})

sortInplace(links, linkSort)
Expand Down
5 changes: 5 additions & 0 deletions test/dag-link-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ module.exports = (repo) => {
.to.equal('12208ab7a6c5e74737878ac73863cb76739d15d4666de44e5756bf55a2f9e9ab5f43')
})

it('empty string', () => {
const link = new DAGLink('', 4, 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U')
expect(link.name).to.be.eql('')
})

it('create with multihash as a multihash Buffer', () => {
const link = new DAGLink('hello', 3, new Buffer('12208ab7a6c5e74737878ac73863cb76739d15d4666de44e5756bf55a2f9e9ab5f43', 'hex'))

Expand Down
16 changes: 13 additions & 3 deletions test/dag-node-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ module.exports = (repo) => {
})
})

it('create with empty link name', (done) => {
DAGNode.create(new Buffer('hello'), [
new DAGLink('', 10, 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U')
], (err, node) => {
expect(err).to.not.exist
expect(node.links[0].name).to.be.eql('')
done()
})
})

it('create an empty node', (done) => {
expect(7).checks(done)
const fromGoIPFS = 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n'
Expand Down Expand Up @@ -134,7 +144,7 @@ module.exports = (repo) => {
.to.eql(node2.multihash)
expect(node1b.links[0].size)
.to.eql(node2.size)
expect(node1b.links[0].name).to.not.exist
expect(node1b.links[0].name).to.be.eql('')
cb()
})
}
Expand Down Expand Up @@ -170,7 +180,7 @@ module.exports = (repo) => {
.to.eql(node2.multihash)
expect(node1b.links[0].size)
.to.eql(node2.size)
expect(node1b.links[0].name).to.not.exist
expect(node1b.links[0].name).to.be.eql('')
cb()
})
}
Expand Down Expand Up @@ -206,7 +216,7 @@ module.exports = (repo) => {
.to.eql(node2.multihash)
expect(node1b.links[0].size)
.to.eql(node2.size)
expect(node1b.links[0].name).to.not.exist
expect(node1b.links[0].name).to.be.eql('')
cb()
})
}
Expand Down
2 changes: 1 addition & 1 deletion test/resolver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('IPLD Format resolver (local)', () => {
let dataLinksNodeBlock

const links = [{
name: undefined,
name: '',
multihash: 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U',
size: 10
}, {
Expand Down

0 comments on commit ad11b7a

Please sign in to comment.