From 2ab46b318f4c9225151c24346cf0ee650e99fc8a Mon Sep 17 00:00:00 2001 From: wanderer Date: Mon, 3 Apr 2017 21:10:41 -0400 Subject: [PATCH 1/2] fixed bug that prevented stings from being encoded --- src/util.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/util.js b/src/util.js index f4fb4ec..5999a83 100644 --- a/src/util.js +++ b/src/util.js @@ -34,7 +34,13 @@ const decoder = new cbor.Decoder({ }) function replaceCIDbyTAG (dagNode) { - if (isCircular(dagNode)) { + let circular + try { + circular = isCircular(dagNode) + } catch (e) { + circular = false + } + if (circular) { throw new Error('The object passed has circular references') } From f17910855bdb145e91e041321ac5ac855321d0c1 Mon Sep 17 00:00:00 2001 From: wanderer Date: Mon, 3 Apr 2017 21:19:56 -0400 Subject: [PATCH 2/2] added tests --- test/util.spec.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/util.spec.js b/test/util.spec.js index 51b8c9c..7daa135 100644 --- a/test/util.spec.js +++ b/test/util.spec.js @@ -62,6 +62,16 @@ describe('util', () => { }) }) + it('strings', (done) => { + dagCBOR.util.cid('some test string', (err, cid) => { + expect(err).to.not.exist() + expect(cid.version).to.equal(1) + expect(cid.codec).to.equal('dag-cbor') + expect(cid.multihash).to.exist() + done() + }) + }) + it.skip('serialize and deserialize - garbage', (done) => { const inputs = []