From a3d6e760f188943ddace37b9d280e70306ffa4e6 Mon Sep 17 00:00:00 2001 From: ifedapoolarewaju Date: Sat, 23 Nov 2019 12:01:41 +0100 Subject: [PATCH] companion: use old url.parse api --- .../@uppy/companion/src/standalone/index.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/@uppy/companion/src/standalone/index.js b/packages/@uppy/companion/src/standalone/index.js index 804d86803..f73af458c 100644 --- a/packages/@uppy/companion/src/standalone/index.js +++ b/packages/@uppy/companion/src/standalone/index.js @@ -1,6 +1,6 @@ const express = require('express') const qs = require('querystring') -const URL = require('url').URL +const urlParser = require('url') const companion = require('../companion') const helmet = require('helmet') const morgan = require('morgan') @@ -53,15 +53,20 @@ morgan.token('url', (req, res) => { morgan.token('referrer', (req, res) => { const ref = req.headers.referer || req.headers.referrer if (typeof ref === 'string') { - const parsed = new URL(ref); + // @todo drop the use of url.parse + // when support for node 6 is dropped + // eslint-disable-next-line + const parsed = urlParser.URL ? new urlParser.URL(ref) : urlParser.parse(ref) + const query = qs.parse(parsed.search.replace('?', '')); ['uppyAuthToken', 'access_token'].forEach(key => { - if (parsed.searchParams.has(key)) { - const token = parsed.searchParams.get(key) - parsed.searchParams.set(key, 'x'.repeat(token.length)) + if (query[key]) { + query[key] = 'x'.repeat(query[key].length) } }) - return parsed.href + const hasQuery = parsed.search + const newURL = `${parsed.href.split('?')[0]}?${qs.stringify(query)}` + return hasQuery ? newURL : parsed.href } })