fix(core): strip closing separators in yaml files (#3198)
This commit is contained in:
parent
4525936136
commit
60ecc72dfa
17
packages/netlify-cms-core/src/formats/__tests__/yaml.spec.js
Normal file
17
packages/netlify-cms-core/src/formats/__tests__/yaml.spec.js
Normal file
@ -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');
|
||||
});
|
||||
});
|
||||
});
|
@ -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);
|
||||
},
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user