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); },