From 93fbf7d4ddecea60709c8379397247af28f11e10 Mon Sep 17 00:00:00 2001 From: Gabriele Coletta Date: Wed, 13 Nov 2019 21:39:39 +0100 Subject: [PATCH] fix issue 526 (wrong quote position writing condensed flow) --- lib/js-yaml/dumper.js | 4 +++- test/issues/0346.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/js-yaml/dumper.js b/lib/js-yaml/dumper.js index 0f5666e3..f3d4fd93 100644 --- a/lib/js-yaml/dumper.js +++ b/lib/js-yaml/dumper.js @@ -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]; diff --git a/test/issues/0346.js b/test/issues/0346.js index ccd75d5b..97519760 100644 --- a/test/issues/0346.js +++ b/test/issues/0346.js @@ -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); });