From 8e05a375adeb519fa5e5aed3d77e8aa43e549383 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Wed, 10 Feb 2021 11:02:58 +0000 Subject: [PATCH] Updated code to reflect js-yaml dependency changes no issue - as per https://github.com/nodeca/js-yaml/blob/master/migrate_v3_to_v4.md, `safeLoad` is now `load` and safe by default, so we can just switch to that --- core/frontend/services/redirects/settings.js | 4 ++-- core/frontend/services/settings/yaml-parser.js | 2 +- test/unit/data/schema/integrity_spec.js | 2 +- test/unit/services/settings/yaml-parser_spec.js | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/frontend/services/redirects/settings.js b/core/frontend/services/redirects/settings.js index 1215fb6e55..c891b2f52a 100644 --- a/core/frontend/services/redirects/settings.js +++ b/core/frontend/services/redirects/settings.js @@ -58,9 +58,9 @@ const parseRedirectsFile = (content, ext) => { if (ext === '.yaml') { let redirects = []; - let configYaml = yaml.safeLoad(content); + let configYaml = yaml.load(content); - // yaml.safeLoad passes almost every yaml code. + // yaml.load passes almost every yaml code. // Because of that, it's hard to detect if there's an error in the file. // But one of the obvious errors is the plain string output. // Here we check if the user made this mistake. diff --git a/core/frontend/services/settings/yaml-parser.js b/core/frontend/services/settings/yaml-parser.js index 98ad85aba3..c222f4e77f 100644 --- a/core/frontend/services/settings/yaml-parser.js +++ b/core/frontend/services/settings/yaml-parser.js @@ -11,7 +11,7 @@ const errors = require('@tryghost/errors'); */ module.exports = function parseYaml(file, fileName) { try { - const parsed = yaml.safeLoad(file); + const parsed = yaml.load(file); debug('YAML settings file parsed:', fileName); diff --git a/test/unit/data/schema/integrity_spec.js b/test/unit/data/schema/integrity_spec.js index aa51e7b291..f7510b9806 100644 --- a/test/unit/data/schema/integrity_spec.js +++ b/test/unit/data/schema/integrity_spec.js @@ -41,7 +41,7 @@ describe('DB version integrity', function () { // and the values above will need updating as confirmation it('should not change without fixing this test', function () { const routesPath = path.join(config.get('paths').defaultSettings, 'default-routes.yaml'); - const defaultRoutes = validateFrontendSettings(yaml.safeLoad(fs.readFileSync(routesPath, 'utf-8'))); + const defaultRoutes = validateFrontendSettings(yaml.load(fs.readFileSync(routesPath, 'utf-8'))); const tablesNoValidation = _.cloneDeep(schema.tables); let schemaHash; diff --git a/test/unit/services/settings/yaml-parser_spec.js b/test/unit/services/settings/yaml-parser_spec.js index 23a36eede1..737f475396 100644 --- a/test/unit/services/settings/yaml-parser_spec.js +++ b/test/unit/services/settings/yaml-parser_spec.js @@ -9,7 +9,7 @@ describe('UNIT > Settings Service yaml parser:', function () { let yamlSpy; beforeEach(function () { - yamlSpy = sinon.spy(yaml, 'safeLoad'); + yamlSpy = sinon.spy(yaml, 'load'); }); afterEach(function () { @@ -35,7 +35,7 @@ describe('UNIT > Settings Service yaml parser:', function () { } catch (error) { should.exist(error); error.message.should.eql('Could not parse badroutes.yaml: bad indentation of a mapping entry.'); - error.context.should.containEql('bad indentation of a mapping entry at line 5, column 14'); + error.context.should.containEql('bad indentation of a mapping entry (5:14)'); error.help.should.eql('Check your badroutes.yaml file for typos and fix the named issues.'); yamlSpy.calledOnce.should.be.true(); }