bencode icon indicating copy to clipboard operation
bencode copied to clipboard

zero in int type

Open interlab opened this issue 10 years ago • 0 comments

https://github.com/rchouinard/bencode/blob/master/src/Decoder.php#L160

i-05e != -5 i05e != 5

Leading zeros are not allowed (although the number zero is still represented as "0").

  1. add after 140 line:
        if ('-' == $this->_getChar($currentOffset) && '0' == $this->_getChar($currentOffset + 1)) {
            throw new RuntimeException('Illegal zero-padding found in integer entity at offset ' . $this->_offset);
        }
  1. find:
        $absoluteValue = (string) abs($value);
        if (1 < strlen($absoluteValue) && "0" == $value[0]) {

replace:

        // $absoluteValue = (string) abs($value);
        if (1 < strlen($value) && '0' == $value[0]) {

interlab avatar Aug 27 '14 10:08 interlab