Skip to content

Commit

Permalink
fix(files): ensure CID in cat() command is only cleaned when input …
Browse files Browse the repository at this point in the history
…is valid

Fixes #799

License: MIT
Signed-off-by: Pascal Precht pascal.precht@gmail.com
  • Loading branch information
0x-r4bbit committed Jul 4, 2018
1 parent 6413fa1 commit 656341e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/files/cat.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ const promisify = require('promisify-es6')
const cleanCID = require('../utils/clean-cid')
const v = require('is-ipfs')
const bl = require('bl')
const CID = require('cids')


function checkValidInput(input) {
return (typeof input === 'string' && (v.cid(input) || v.ipfsPath(input))) || (Buffer.isBuffer(input) || CID.isCID(input))
}

module.exports = (send) => {
return promisify((hash, opts, callback) => {
Expand All @@ -13,7 +19,9 @@ module.exports = (send) => {
}

try {
hash = cleanCID(hash)
if (checkValidInput(hash)) {
hash = cleanCID(hash)
}
} catch (err) {
if (!v.ipfsPath(hash)) {
return callback(err)
Expand Down

0 comments on commit 656341e

Please sign in to comment.