fix(core): strip closing separators in yaml files (#3198)

This commit is contained in:
Shawn Erquhart 2020-02-05 03:14:40 -05:00 committed by GitHub
parent 4525936136
commit 60ecc72dfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View 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');
});
});
});

View File

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