From 60ecc72dfab660eea795fb1307df8596d65cd78b Mon Sep 17 00:00:00 2001 From: Shawn Erquhart Date: Wed, 5 Feb 2020 03:14:40 -0500 Subject: [PATCH] fix(core): strip closing separators in yaml files (#3198) --- .../src/formats/__tests__/yaml.spec.js | 17 +++++++++++++++++ packages/netlify-cms-core/src/formats/yaml.js | 3 +++ 2 files changed, 20 insertions(+) create mode 100644 packages/netlify-cms-core/src/formats/__tests__/yaml.spec.js diff --git a/packages/netlify-cms-core/src/formats/__tests__/yaml.spec.js b/packages/netlify-cms-core/src/formats/__tests__/yaml.spec.js new file mode 100644 index 00000000..520dfb80 --- /dev/null +++ b/packages/netlify-cms-core/src/formats/__tests__/yaml.spec.js @@ -0,0 +1,17 @@ +import yaml from '../yaml'; + +describe('yaml', () => { + describe('fromFile', () => { + test('loads valid yaml', () => { + expect(yaml.fromFile('[]')).toEqual([]); + }); + test('does not fail on closing separator', () => { + expect(yaml.fromFile('---\n[]\n---')).toEqual([]); + }); + }); + describe('toFile', () => { + test('outputs valid yaml', () => { + expect(yaml.toFile([])).toEqual('[]\n'); + }); + }); +}); diff --git a/packages/netlify-cms-core/src/formats/yaml.js b/packages/netlify-cms-core/src/formats/yaml.js index 18d26a64..cc29b595 100644 --- a/packages/netlify-cms-core/src/formats/yaml.js +++ b/packages/netlify-cms-core/src/formats/yaml.js @@ -37,6 +37,9 @@ const OutputSchema = new yaml.Schema({ export default { fromFile(content) { + if (content && content.trim().endsWith('---')) { + content = content.trim().slice(0, -3); + } return yaml.safeLoad(content); },