From 9972898d51e53eccd14f6634180e51cd5856b227 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Wed, 14 Aug 2019 21:00:08 +0200 Subject: [PATCH] fix: preload addreses with trailing slash - moves path utils to upstream utils - closes #2333 License: MIT Signed-off-by: Marcin Rataj --- src/core/preload.js | 4 +++- src/http/gateway/resources/gateway.js | 2 +- src/{http/gateway => }/utils/path.js | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) rename src/{http/gateway => }/utils/path.js (95%) diff --git a/src/core/preload.js b/src/core/preload.js index 983b0445d1..390613125b 100644 --- a/src/core/preload.js +++ b/src/core/preload.js @@ -7,6 +7,7 @@ const debug = require('debug') const CID = require('cids') const shuffle = require('array-shuffle') const preload = require('./runtime/preload-nodejs') +const { removeTrailingSlash } = require('../utils/path') const log = debug('ipfs:preload') log.error = debug('ipfs:preload:error') @@ -86,7 +87,8 @@ module.exports = self => { } function apiAddrToUri (addr) { - if (!(addr.endsWith('http') || addr.endsWith('https'))) { + addr = removeTrailingSlash(addr) + if (!(addr.endsWith('/http') || addr.endsWith('/https') || addr.endsWith('/tls/http'))) { addr = addr + '/http' } return toUri(addr) diff --git a/src/http/gateway/resources/gateway.js b/src/http/gateway/resources/gateway.js index ccdc8aa68b..f17c0f7aab 100644 --- a/src/http/gateway/resources/gateway.js +++ b/src/http/gateway/resources/gateway.js @@ -12,7 +12,7 @@ const peek = require('buffer-peek-stream') const multibase = require('multibase') const { resolver } = require('ipfs-http-response') -const PathUtils = require('../utils/path') +const PathUtils = require('../../../utils/path') const { cidToString } = require('../../../utils/cid') const isIPFS = require('is-ipfs') diff --git a/src/http/gateway/utils/path.js b/src/utils/path.js similarity index 95% rename from src/http/gateway/utils/path.js rename to src/utils/path.js index a7f6a58072..a1d10dcb70 100644 --- a/src/http/gateway/utils/path.js +++ b/src/utils/path.js @@ -17,7 +17,7 @@ function removeLeadingSlash (url) { } function removeTrailingSlash (url) { - if (url.endsWith('/')) { + if (url && url.endsWith('/')) { url = url.substring(0, url.length - 1) }