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

Commit

Permalink
fix: Ensure inputs are not modified
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Apr 9, 2016
1 parent cb8267d commit b20f90b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"dependencies": {
"bs58": "^3.0.0",
"cbor": "^1.0.1",
"lodash.clonedeep": "^4.3.2",
"lodash.defaults": "^4.0.1",
"lodash.includes": "^4.1.2",
"multiaddr": "^1.3.0",
Expand Down
5 changes: 4 additions & 1 deletion src/cbor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ const Multiaddr = require('multiaddr')
const NoFilter = require('nofilter')
const defaults = require('lodash.defaults')
const includes = require('lodash.includes')
const cloneDeep = require('lodash.cloneDeep')

exports = module.exports

exports.LINK_TAG = 258

exports.marshal = (input) => {
exports.marshal = (original) => {
const input = cloneDeep(original)

function transform (obj) {
const keys = Object.keys(obj)

Expand Down
1 change: 0 additions & 1 deletion src/multihash.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const crypto = require('crypto')
const multihashing = require('multihashing')
const bs58 = require('bs58')

Expand Down
12 changes: 12 additions & 0 deletions test/cbor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@ describe('IPLD -> CBOR', () => {
cbor.encode(expected)
)
})

it('does not modify the input', () => {
let src = {
'@link': 'hello'
}

ipld.marshal(src)

expect(src).to.be.eql({
'@link': 'hello'
})
})
})

describe('CBOR -> IPLD', () => {
Expand Down

0 comments on commit b20f90b

Please sign in to comment.