fix: json FM ending with object parse error (#4909)
This commit is contained in:
parent
e481e6e296
commit
60454bb4de
@ -351,6 +351,18 @@ describe('Frontmatter', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should parse JSON with { } delimiters ending with a nested object', () => {
|
||||
expect(
|
||||
FrontmatterInfer.fromFile(
|
||||
'{\n "title": "The Title",\n "nested": {\n "inside": "Inside prop"\n }\n}\nContent',
|
||||
),
|
||||
).toEqual({
|
||||
title: 'The Title',
|
||||
nested: { inside: 'Inside prop' },
|
||||
body: 'Content',
|
||||
});
|
||||
});
|
||||
|
||||
it('should stringify JSON with { } delimiters when it is explicitly set as the format without a custom delimiter', () => {
|
||||
expect(
|
||||
frontmatterJSON().toFile({
|
||||
|
@ -13,10 +13,7 @@ const parsers = {
|
||||
let JSONinput = input.trim();
|
||||
// Fix JSON if leading and trailing brackets were trimmed.
|
||||
if (JSONinput.substr(0, 1) !== '{') {
|
||||
JSONinput = '{' + JSONinput;
|
||||
}
|
||||
if (JSONinput.substr(-1) !== '}') {
|
||||
JSONinput = JSONinput + '}';
|
||||
JSONinput = '{' + JSONinput + '}';
|
||||
}
|
||||
return jsonFormatter.fromFile(JSONinput);
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user