bytebuffer.js icon indicating copy to clipboard operation
bytebuffer.js copied to clipboard

ByteBuffer.fromHex returns an empty buffer for non-hex characters

Open recursify opened this issue 10 years ago • 1 comments

Using version 3.5.5 with nodejs v0.12.4

var ByteBuffer = require('bytebuffer')
var a = ByteBuffer.fromHex('vvzzkk', true, false)
console.log(a);
var b = ByteBuffer.fromHex('vvzzkk', true, true)
console.log(b);

prints

{ buffer: <Buffer >,
  offset: 0,
  markedOffset: -1,
  limit: 0,
  littleEndian: true,
  noAssert: true }
{ buffer: <Buffer >,
  offset: 0,
  markedOffset: -1,
  limit: 0,
  littleEndian: true,
  noAssert: true }

I would expect it to throw an error for non-hex characters, given https://github.com/dcodeIO/ByteBuffer.js/blob/master/src/encodings/hex.js#L65

recursify avatar Aug 04 '15 23:08 recursify

Hmm, in the node case, it's hardcoding noAssert to true... is that intentional?

https://github.com/dcodeIO/ByteBuffer.js/blob/master/src/encodings/hex.js#L53

recursify avatar Aug 05 '15 00:08 recursify