fix encoding of empty string in TXT data - fixes #39
This commit is contained in:
parent
e29a832aa8
commit
db4e271a59
3
index.js
3
index.js
@ -1238,7 +1238,8 @@ answer.decode = function (buf, offset) {
|
||||
answer.decode.bytes = 0
|
||||
|
||||
answer.encodingLength = function (a) {
|
||||
return name.encodingLength(a.name) + 8 + renc(a.type).encodingLength(a.data || a.options)
|
||||
const data = (a.data !== null && a.data !== undefined) ? a.data : a.options
|
||||
return name.encodingLength(a.name) + 8 + renc(a.type).encodingLength(data)
|
||||
}
|
||||
|
||||
const question = exports.question = {}
|
||||
|
||||
16
test.js
16
test.js
@ -221,6 +221,15 @@ tape('response', function (t) {
|
||||
}]
|
||||
})
|
||||
|
||||
testEncoder(t, packet, {
|
||||
type: 'response',
|
||||
answers: [{
|
||||
type: 'TXT',
|
||||
name: 'emptytxt.com',
|
||||
data: ''
|
||||
}]
|
||||
})
|
||||
|
||||
t.end()
|
||||
})
|
||||
|
||||
@ -497,8 +506,13 @@ function compare (t, a, b) {
|
||||
if (typeof a === 'object' && a && b) {
|
||||
const keys = Object.keys(a)
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
if (!compare(t, a[keys[i]], b[keys[i]])) return false
|
||||
if (!compare(t, a[keys[i]], b[keys[i]])) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
} else if (Array.isArray(b) && !Array.isArray(a)) {
|
||||
// TXT always decode as array
|
||||
return a.toString() === b[0].toString()
|
||||
} else {
|
||||
return a === b
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user