diff --git a/lib/bootstrap.js b/lib/bootstrap.js index bcb3720ab..a81f03350 100644 --- a/lib/bootstrap.js +++ b/lib/bootstrap.js @@ -6,7 +6,7 @@ const _ = require('lodash'); const merger = require('./config').merge; const fs = require('fs'); const path = require('path'); -const yaml = require('js-yaml'); +const {load} = require('js-yaml'); /** * Docker and Compose version metadata. @@ -110,7 +110,7 @@ const loadCacheFile = file => { */ const loadLandoFile = file => { try { - return yaml.load(fs.readFileSync(file)); + return load(fs.readFileSync(file, {encoding: 'utf-8'})); } catch (e) { throw new Error(`There was a problem with parsing ${file}. Ensure it is valid YAML! ${e}`, {cause: e}); } diff --git a/lib/config.js b/lib/config.js index 4b98d9dcd..0edfecbee 100644 --- a/lib/config.js +++ b/lib/config.js @@ -6,7 +6,7 @@ const env = require('./env'); const fs = require('fs'); const path = require('path'); const os = require('os'); -const yaml = require('js-yaml'); +const {load} = require('js-yaml'); const url = require('url'); /** @@ -223,7 +223,7 @@ exports.loadFiles = files => _(files) }) // If the file is just a string lets map it to an object .map(source => { - return _.isString(source) ? {file: source, data: yaml.load(fs.readFileSync(source)) || {}} : source; + return _.isString(source) ? {file: source, data: load(fs.readFileSync(source, 'utf-8')) || {}} : source; }) // Add on the root directory for mapping purposes .map(source => _.merge({}, source, {root: path.dirname(source.file)})) diff --git a/lib/yaml.js b/lib/yaml.js index 0ff21e574..2f9437770 100644 --- a/lib/yaml.js +++ b/lib/yaml.js @@ -4,7 +4,7 @@ const fs = require('fs'); const Log = require('./logger'); const path = require('path'); -const yaml = require('js-yaml'); +const {dump, load} = require('js-yaml'); /** * YAML helper for reading and writing config files. @@ -30,7 +30,7 @@ module.exports = class Yaml { */ load(file) { try { - return yaml.load(fs.readFileSync(file)); + return load(fs.readFileSync(file, {encoding: 'utf-8'})); } catch (e) { this.log.error('Problem parsing %s with %s', file, e.message); } @@ -50,7 +50,7 @@ module.exports = class Yaml { // Remove any properties that might be bad and dump data = JSON.parse(JSON.stringify(data)); // And dump - fs.writeFileSync(file, yaml.dump(data)); + fs.writeFileSync(file, dump(data)); // Log and return filename return file; }; diff --git a/package-lock.json b/package-lock.json index 271afefb8..6646a70cf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "copy-dir": "^1.3.0", "dockerode": "^5.0.1", "glob": "^13.0.0", - "js-yaml": "^4.3.0", + "js-yaml": "^5.4.1", "jsonfile": "^6.2.1", "lodash": "^4.18.1", "node-cache": "^5.1.2", @@ -4467,9 +4467,9 @@ "license": "MIT" }, "node_modules/js-yaml": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.0.tgz", - "integrity": "sha512-1td788aAnnZ5qs7V2QIRl1owjtYpbKt749Y3xauqQgwIIGF/xXWz1wMTEBx5O3LK3lXLVuqXPdPxj2BoFHaW9Q==", + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-5.4.1.tgz", + "integrity": "sha512-28R/k+NAjeuf7+CKlTxWZVExJGwVVLwY06DgEnOMz2gEpfNkDcD7QvyiVPT0xy0XXhU8vHsd4Ot42OOPdJG7dQ==", "funding": [ { "type": "github", @@ -4485,7 +4485,7 @@ "argparse": "^2.0.1" }, "bin": { - "js-yaml": "bin/js-yaml.js" + "js-yaml": "bin/js-yaml.mjs" } }, "node_modules/jsdoc-type-pratt-parser": { @@ -5428,6 +5428,29 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/mocha/node_modules/js-yaml": { + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.3.2.tgz", + "integrity": "sha512-SFNOvSJ+Dgf/9An904Yx+CgSlIPCkIpao4qo51lpee25TIRejdH3rhR4EZMGoNx3/TP3O+wzWuiTFl4sqbltzA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/puzrin" + }, + { + "type": "github", + "url": "https://github.com/sponsors/nodeca" + } + ], + "license": "MIT", + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, "node_modules/mocha/node_modules/lru-cache": { "version": "10.4.3", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", diff --git a/package.json b/package.json index 1503c431c..f12e8809b 100644 --- a/package.json +++ b/package.json @@ -104,7 +104,7 @@ "copy-dir": "^1.3.0", "dockerode": "^5.0.1", "glob": "^13.0.0", - "js-yaml": "^4.3.0", + "js-yaml": "^5.4.1", "jsonfile": "^6.2.1", "lodash": "^4.18.1", "node-cache": "^5.1.2", diff --git a/plugins/lando-proxy/lib/utils.js b/plugins/lando-proxy/lib/utils.js index f3c3aadc8..357d24a01 100644 --- a/plugins/lando-proxy/lib/utils.js +++ b/plugins/lando-proxy/lib/utils.js @@ -247,16 +247,28 @@ exports.parseUrl = data => { // We add the protocol ourselves, so it can be parsed. We also change all * // occurrences for our magic word __wildcard__, because otherwise the url parser // won't parse wildcards in the hostname correctly. - const parsedUrl = _.isString(data) ? url.parse(`http://${data}`.replace(/\*/g, '__wildcard__')) : _.merge({}, data, { - hostname: data.hostname.replace(/\*/g, '__wildcard__'), - }); + let parsedUrl; + if (typeof data === 'string') { + const u = new URL(`http://${data}`); + parsedUrl = {...url.urlToHttpOptions(u)}; + ['port', 'hash', 'search'].forEach(prop => { + parsedUrl[prop] ||= null; + }); + parsedUrl.query = u.searchParams.toString(); + if (parsedUrl.port) { + parsedUrl.port = parsedUrl.port.toString(); + } + parsedUrl.host = u.host; + } else { + parsedUrl = {...data}; + } // If the port is null then set it to 80 if (_.isNil(parsedUrl.port)) parsedUrl.port = '80'; // Retranslate and send const defaults = {port: '80', pathname: '/', middlewares: []}; - return _.merge(defaults, parsedUrl, {host: parsedUrl.hostname.replace(/__wildcard__/g, '*')}); + return _.merge(defaults, parsedUrl, {host: parsedUrl}); }; /**