From ab777d2e3ff2d31d72d5fb2d9b8741efe4915a9d Mon Sep 17 00:00:00 2001 From: Nitin Patel Date: Thu, 14 Mar 2019 18:21:34 +0530 Subject: [PATCH] fix: handle subdomains for ipfs.dns --- src/core/runtime/dns-nodejs.js | 6 ++++-- test/cli/dns.js | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/core/runtime/dns-nodejs.js b/src/core/runtime/dns-nodejs.js index a3d583ef92..6c3915fc75 100644 --- a/src/core/runtime/dns-nodejs.js +++ b/src/core/runtime/dns-nodejs.js @@ -7,8 +7,10 @@ const errcode = require('err-code') module.exports = (domain, opts, callback) => { resolveDnslink(domain) .catch(err => { - // If the code is not ENOTFOUND or ERR_DNSLINK_NOT_FOUND then throw the error - if (err.code !== 'ENOTFOUND' && err.code !== 'ERR_DNSLINK_NOT_FOUND') throw err + // If the code is not ENOTFOUND or ERR_DNSLINK_NOT_FOUND or ENODATA then throw the error + if (err.code !== 'ENOTFOUND' && err.code !== 'ERR_DNSLINK_NOT_FOUND' && err.code !== 'ENODATA') { + throw err + } if (domain.startsWith('_dnslink.')) { // The supplied domain contains a _dnslink component diff --git a/test/cli/dns.js b/test/cli/dns.js index 55aea6f5b6..09286aa325 100644 --- a/test/cli/dns.js +++ b/test/cli/dns.js @@ -27,4 +27,20 @@ describe('dns', () => runOnAndOff((thing) => { expect(res.substr(0, 6)).to.eql('/ipns/') }) }) + + it('resolve subdomain docs.ipfs.io dns', function () { + this.timeout(60 * 1000) + + return ipfs('dns docs.ipfs.io').then(res => { + expect(res.substr(0, 6)).to.eql('/ipfs/') + }) + }) + + it('resolve subdomain _dnslink.docs.ipfs.io dns', function () { + this.timeout(60 * 1000) + + return ipfs('dns _dnslink.docs.ipfs.io').then(res => { + expect(res.substr(0, 6)).to.eql('/ipfs/') + }) + }) }))