Merge pull request #556 from sinistersig/next
Ensure toString is not called on buffers
This commit is contained in:
commit
4b2e55e111
|
@ -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())
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 740 B |
Loading…
Reference in New Issue