node-dig-dns icon indicating copy to clipboard operation
node-dig-dns copied to clipboard

potential bugfix for TXT records splitting after whitespace

Open lastarel opened this issue 4 years ago • 3 comments

Hi,

For TXT records that can have whitespaces such as: SPF records: IE: "v=spf1 include:_spf.google.com ~all" Prior to commit this would've been parsed as: dig(['google.com','TXT']).then((res)=>{ console.log(res.answer) })

{ domain: 'google.com.', type: 'TXT', ttl: '3591', class: 'IN', value: '~all"' },

Post commit: dig(['google.com','TXT']).then((res)=>{ console.log(res.answer) })

{ domain: 'google.com.', type: 'TXT', ttl: '3561', class: 'IN', value: '"v=spf1 include:_spf.google.com ~all"' },

lastarel avatar Oct 12 '21 11:10 lastarel

Hi @lastarel

Thank you for the PR. Could you please write a test for your scenario so I can review your changes?

StephanGeorg avatar Oct 13 '21 07:10 StephanGeorg

Hi,

Not really sure what you refer to by a test as I've commented above pre-post the responses received.

As to not make another commit with a simple test you can run this test : it('Should query TXT for spf.test.com and return a full valid value for spf', (done) => { dig(['spf.test.com', 'TXT']) .then((result) => { expect(result).to.be.an('object') .and.to.have.property('question') .and.to.be.an('array'); expect(result).to.have.property('answer') .and.to.be.an('array'); expect(result.answer[0].value).to.be.a('string') expect(result).to.have.property('time') .and.to.be.an('number'); expect(result).to.have.property('server') .and.to.be.an('string'); expect(result).to.have.property('datetime') .and.to.be.an('string'); expect(result).to.have.property('size') .and.to.be.an('number'); expect(result.answer[0].value).to.contain('v=spf1 ~all') expect(result.answer[0].type).to.equal("TXT") done(); }) .catch((err) => { console.log('Error:', err); }); }); It's a spin from your MX test so you can check the properties and values as well as the TXT return value. Good luck hope it helps.

lastarel avatar Oct 13 '21 08:10 lastarel

This bugfix uses joins(' ') to re-combine the improperly split TXT record by the previous line.split(/\s+/g). This does not work for a train of consecutive whitespaces inside the TXT record.

clementcheung avatar Nov 03 '21 06:11 clementcheung