diff options
author | Ruy Adorno <ruyadorno@hotmail.com> | 2020-10-29 22:39:51 +0300 |
---|---|---|
committer | Ruy Adorno <ruyadorno@hotmail.com> | 2020-10-30 20:46:08 +0300 |
commit | 3109d36f651063f771b6735e89a3db5850f1d1b5 (patch) | |
tree | d5bfb4a30c2ee6a2f9dc2f47ba279e8066f62023 /lib/utils | |
parent | e34f975182aec3d2a86f3cf28b8d5ecfb30690ee (diff) |
test: add tests for test/lib/utils/replace-info.js
Diffstat (limited to 'lib/utils')
-rw-r--r-- | lib/utils/error-message.js | 6 | ||||
-rw-r--r-- | lib/utils/replace-info.js | 33 |
2 files changed, 26 insertions, 13 deletions
diff --git a/lib/utils/error-message.js b/lib/utils/error-message.js index 8b459e643..04034243f 100644 --- a/lib/utils/error-message.js +++ b/lib/utils/error-message.js @@ -12,8 +12,10 @@ module.exports = (er) => { const short = [] const detail = [] - er.message = replaceInfo(er.message) - er.stack = replaceInfo(er.stack) + if (er.message) + er.message = replaceInfo(er.message) + if (er.stack) + er.stack = replaceInfo(er.stack) switch (er.code) { case 'ERESOLVE': diff --git a/lib/utils/replace-info.js b/lib/utils/replace-info.js index a613a3755..e3e324c88 100644 --- a/lib/utils/replace-info.js +++ b/lib/utils/replace-info.js @@ -1,22 +1,33 @@ -const URL = require('url') +'use strict' -// replaces auth info in an array -// of arguments or in a strings +const URL = require('url').URL + +// replaces auth info in an array of arguments or in a strings function replaceInfo (arg) { const isArray = Array.isArray(arg) - const isString = typeof arg === 'string' + const isString = str => typeof str === 'string' - if (!isArray && !isString) return arg + if (!isArray && !isString(arg)) + return arg - const args = isString ? arg.split(' ') : arg - const info = args.map(arg => { + const testUrlAndReplace = str => { try { - const url = new URL(arg) - return url.password === '' ? arg : arg.replace(url.password, '***') - } catch (e) { return arg } + const url = new URL(str) + return url.password === '' ? str : str.replace(url.password, '***') + } catch (e) { + return str + } + } + + const args = isString(arg) ? arg.split(' ') : arg + const info = args.map(a => { + if (isString(a) && a.indexOf(' ') > -1) + return a.split(' ').map(testUrlAndReplace).join(' ') + + return testUrlAndReplace(a) }) - return isString ? info.join(' ') : info + return isString(arg) ? info.join(' ') : info } module.exports = replaceInfo |