davidmarkclements / rfdc

Really Fast Deep Clone
MIT License
635 stars 24 forks source link

Does not support cloning Buffers #18

Closed salmanm closed 3 years ago

salmanm commented 3 years ago

All versions of clone do not support copying Buffers. There are 2 different problems

Scenario 1

const clone = require('rfdc')()
const res = clone({ a: Buffer.from('ab') })

Actual Output

{ a: { '0': 97, '1': 98 } }

The buffer is incorrectly interpreted as an object and returned value is wrong.

Expected

{ a: <Buffer 61 62> }

Scenario 2

const clone = require('rfdc')({ proto: true })
const res = clone({ a: Buffer.from('') })

Output

{
  a: {
    readBigUInt64LE: [Function: readBigUInt64LE],
    readBigUInt64BE: [Function: readBigUInt64BE],
    readBigInt64LE: [Function: readBigInt64LE],
    readBigInt64BE: [Function: readBigInt64BE],
    writeBigUInt64LE: [Function: writeBigUInt64LE],
    ...
  }
}

The buffer's internals are copied into output

Expected

{ a: <Buffer 61 62> }