diff --git a/index.js b/index.js index 5a56753..0a52015 100644 --- a/index.js +++ b/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 = {} diff --git a/test.js b/test.js index 780dd12..b7a4552 100644 --- a/test.js +++ b/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 }