Skip to content

Commit

Permalink
Fix issue #526: wrong quote position writing condensed flow (#527)
Browse files Browse the repository at this point in the history
Fix issue #526: wrong quote position writing condensed flow
  • Loading branch information
Vitaly Puzrin authored Nov 15, 2019
2 parents e569cc7 + 93fbf7d commit d6983dd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/js-yaml/dumper.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,12 @@ function writeFlowMapping(state, level, object) {
pairBuffer;

for (index = 0, length = objectKeyList.length; index < length; index += 1) {
pairBuffer = state.condenseFlow ? '"' : '';

pairBuffer = '';
if (index !== 0) pairBuffer += ', ';

if (state.condenseFlow) pairBuffer += '"';

objectKey = objectKeyList[index];
objectValue = object[objectKey];

Expand Down
4 changes: 2 additions & 2 deletions test/issues/0346.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ test('should not emit spaces in arrays in flow mode between entries using conden
});

test('should not emit spaces between key: value and quote keys using condenseFlow: true', function () {
var object = { a: { b: 'c' } };
var object = { a: { b: 'c', d: 'e' } };
var objectDump = yaml.dump(object, { flowLevel: 0, indent: 0, condenseFlow: true });
assert.equal(
objectDump,
'{"a":{"b":c}}\n'
'{"a":{"b":c, "d":e}}\n'
);
assert.deepEqual(yaml.load(objectDump), object);
});

0 comments on commit d6983dd

Please sign in to comment.