Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Invalid data: Missing delimiter ":" [0x3a] #36

Closed
akayami opened this issue Feb 3, 2016 · 5 comments
Closed

Error: Invalid data: Missing delimiter ":" [0x3a] #36

akayami opened this issue Feb 3, 2016 · 5 comments

Comments

@akayami
Copy link

akayami commented Feb 3, 2016

Hi,

In the following code:

const crypto = require('crypto');
const bencode = require('bencode');

console.log(bencode.decode(bencode.encode({a: 'false'})));
console.log(bencode.decode(bencode.encode({a: false})))

I'm getting:

Error: Invalid data: Missing delimiter ":" [0x3a]
    at Function.decode.find (/home/tomasz/dev/git/payment-processor/node_modules/bencode/lib/decode.js:50:9)
    at Function.decode.bytes (/home/tomasz/dev/git/payment-processor/node_modules/bencode/lib/decode.js:103:23)
    at Function.decode.next (/home/tomasz/dev/git/payment-processor/node_modules/bencode/lib/decode.js:33:30)
    at Function.decode.dictionary (/home/tomasz/dev/git/payment-processor/node_modules/bencode/lib/decode.js:65:43)
    at Function.decode.next (/home/tomasz/dev/git/payment-processor/node_modules/bencode/lib/decode.js:30:30)
    at Object.decode (/home/tomasz/dev/git/payment-processor/node_modules/bencode/lib/decode.js:19:17)
    at Object.<anonymous> (/home/tomasz/dev/git/payment-processor/test/sample.js:5:21)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)

Any object containing a boolean as a value on any key causes decode to fail.

@themasch
Copy link
Sponsor Contributor

themasch commented Feb 4, 2016

Okay, the problem in this case is that there is (at least to my knowledge) no way to store a boolean in bencode. But we surely need to handle this better.

What would be the best way to handle it?
a) throw an exception because booleans aren't supported
b) cast the boolean to string and encode it
c) cast the boolean to a int and encode it (1 | 0)
d) invent a new bencode-tag to store booleans (meh!)

I'd vote for (c) because at least "0 == false" works. If we are doing strings, "'false' == false" will fail.

@jhermsmeier
Copy link
Collaborator

I'd go with option (c) as well - seems the least intrusive while still being compatible with the spec. Option (a) would seem more correct to me, but less convenient.

@themasch
Copy link
Sponsor Contributor

Someone (@kaelar) already implemented that in the @bittorrent fork of this project (bittorrent@f3f75a3).

@jhermsmeier
Copy link
Collaborator

Oh, wasn't aware of that. @kaelar, fancy sending a PR our way?

@jhermsmeier
Copy link
Collaborator

It's now fixed & published as 0.8.0 (see #38)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants