Ensure toString is not called on buffers

This commit is contained in:
sinistersig 2019-09-06 11:27:37 +01:00
parent d6f58e6487
commit 06b1804d32
3 changed files with 24 additions and 0 deletions

View File

@ -81,6 +81,8 @@ Object.defineProperties(Change.prototype, {
val[k].forEach(function (v) { val[k].forEach(function (v) {
_attr.addValue(v.toString()) _attr.addValue(v.toString())
}) })
} else if (Buffer.isBuffer(val[k])) {
_attr.addValue(val[k])
} else if (val[k] !== undefined && val[k] !== null) { } else if (val[k] !== undefined && val[k] !== null) {
_attr.addValue(val[k].toString()) _attr.addValue(val[k].toString())
} }

View File

@ -1,5 +1,7 @@
'use strict' 'use strict'
const fs = require('fs')
const path = require('path')
const { test } = require('tap') const { test } = require('tap')
const { BerReader, BerWriter } = require('asn1') const { BerReader, BerWriter } = require('asn1')
const { Attribute, Change } = require('../lib') const { Attribute, Change } = require('../lib')
@ -28,6 +30,26 @@ test('new with args', function (t) {
t.end() t.end()
}) })
test('new with args and buffer', function (t) {
var img = fs.readFileSync(path.join(__dirname, '/imgs/test.jpg'))
var change = new Change({
operation: 'add',
modification: {
thumbnailPhoto: img
}
})
t.ok(change)
t.equal(change.operation, 'add')
t.equal(change.modification.type, 'thumbnailPhoto')
t.equal(change.modification.vals.length, 1)
t.equal(change.modification.buffers[0].compare(img), 0)
t.end()
})
test('validate fields', function (t) { test('validate fields', function (t) {
const c = new Change() const c = new Change()
t.ok(c) t.ok(c)

BIN
test/imgs/test.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 740 B