Giter Site home page Giter Site logo

bencode's People

Contributors

ap avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

natefriedman

bencode's Issues

Need clear behavior for strings with utf8 flag set

The base bencoding format specifies encoding only for strings of bytes, not Unicode strings. When decoding, there is no way to distinguish if the original data was an UTF-8 string or a byte buffer that appears to look like an UTF-8 string.

The module documentation should clearly specify (and the implementation be tested) how Perl strings with the utf8 flag given in the input to bencode will be handled. Throwing an exception would be an appropriate behavior, in order to force the user of the module to properly encode its data as bytes.

The bdecode function should clearly disallow a string of characters and allow only a string of bytes.

Warnings thrown on 'undef' elements

When passing a Perl structure containing 'undef' values to the 'bencode' subroutine like so:

use Bencode qw/bencode bdecode/;
use Data::Dumper;

my $x = [1,2,undef,4];
my $b = bencode($x);
warn $b;

my $c = bdecode($b);
warn Dumper($c);

warnings are generated and the result appears to be invalid Bencode.

Use of uninitialized value $data in pattern match (m//) at /home/mark/src/bif/.direnv/perl5/lib/perl5/Bencode.pm line 120.
Use of uninitialized value $data in concatenation (.) or string at /home/mark/src/bif/.direnv/perl5/lib/perl5/Bencode.pm line 121.
Use of uninitialized value $data in concatenation (.) or string at /home/mark/src/bif/.direnv/perl5/lib/perl5/Bencode.pm line 121.
li1ei2e:i4ee at x.pl line 11.
garbage at 7 at x.pl line 13.

I am aware that the original format doesn't cover undefined values, so you probably don't want to support round-tripping of 'undef'. But I would suggest either croaking or encoding a zero-length string in place of the undef (configurable by an option?) to be better than invalid output.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.