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

Commit ad11b7a

Browse files
fix: ensure empty link names are preserved
1 parent 72c7223 commit ad11b7a

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

src/dag-node/create.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ function create (data, dagLinks, hashAlg, callback) {
3333
}
3434

3535
return new DAGLink(
36-
l.name || l.Name,
37-
l.size || l.Size,
38-
l.hash || l.Hash || l.multihash)
36+
l.name != null ? l.name : l.Name,
37+
l.size != null ? l.size : l.Size,
38+
l.hash || l.Hash || l.multihash
39+
)
3940
})
4041

4142
sortInplace(links, linkSort)

test/dag-link-test.js

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ module.exports = (repo) => {
1515
.to.equal('12208ab7a6c5e74737878ac73863cb76739d15d4666de44e5756bf55a2f9e9ab5f43')
1616
})
1717

18+
it('empty string', () => {
19+
const link = new DAGLink('', 4, 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U')
20+
expect(link.name).to.be.eql('')
21+
})
22+
1823
it('create with multihash as a multihash Buffer', () => {
1924
const link = new DAGLink('hello', 3, new Buffer('12208ab7a6c5e74737878ac73863cb76739d15d4666de44e5756bf55a2f9e9ab5f43', 'hex'))
2025

test/dag-node-test.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ module.exports = (repo) => {
8585
})
8686
})
8787

88+
it('create with empty link name', (done) => {
89+
DAGNode.create(new Buffer('hello'), [
90+
new DAGLink('', 10, 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U')
91+
], (err, node) => {
92+
expect(err).to.not.exist
93+
expect(node.links[0].name).to.be.eql('')
94+
done()
95+
})
96+
})
97+
8898
it('create an empty node', (done) => {
8999
expect(7).checks(done)
90100
const fromGoIPFS = 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n'
@@ -134,7 +144,7 @@ module.exports = (repo) => {
134144
.to.eql(node2.multihash)
135145
expect(node1b.links[0].size)
136146
.to.eql(node2.size)
137-
expect(node1b.links[0].name).to.not.exist
147+
expect(node1b.links[0].name).to.be.eql('')
138148
cb()
139149
})
140150
}
@@ -170,7 +180,7 @@ module.exports = (repo) => {
170180
.to.eql(node2.multihash)
171181
expect(node1b.links[0].size)
172182
.to.eql(node2.size)
173-
expect(node1b.links[0].name).to.not.exist
183+
expect(node1b.links[0].name).to.be.eql('')
174184
cb()
175185
})
176186
}
@@ -206,7 +216,7 @@ module.exports = (repo) => {
206216
.to.eql(node2.multihash)
207217
expect(node1b.links[0].size)
208218
.to.eql(node2.size)
209-
expect(node1b.links[0].name).to.not.exist
219+
expect(node1b.links[0].name).to.be.eql('')
210220
cb()
211221
})
212222
}

test/resolver.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('IPLD Format resolver (local)', () => {
1717
let dataLinksNodeBlock
1818

1919
const links = [{
20-
name: undefined,
20+
name: '',
2121
multihash: 'QmXg9Pp2ytZ14xgmQjYEiHjVjMFXzCVVEcRTWJBmLgR39U',
2222
size: 10
2323
}, {

0 commit comments

Comments
 (0)