From 29072a5224252c6ba63598bb2dd3abe572b17a74 Mon Sep 17 00:00:00 2001 From: Nitin Patel <31539366+niinpatel@users.noreply.github.com> Date: Wed, 20 Mar 2019 14:35:24 +0530 Subject: [PATCH] fix: handle subdomains for ipfs.dns (#1933) --- src/core/runtime/dns-nodejs.js | 4 ++-- test/cli/dns.js | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/core/runtime/dns-nodejs.js b/src/core/runtime/dns-nodejs.js index a3d583ef92..d187ed0915 100644 --- a/src/core/runtime/dns-nodejs.js +++ b/src/core/runtime/dns-nodejs.js @@ -7,8 +7,8 @@ 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/') + }) + }) }))