Skip to content

Commit

Permalink
don't use block-style-only string literals in flow mode
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunc committed Jan 9, 2016
1 parent 0fbab05 commit 8d06176
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/js-yaml/dumper.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,12 @@ function writeScalar(state, object, level, iskey) {
simple = false;
}

// can only use > and | if not wrapped in spaces or is not a key.
if (spaceWrap) {
simple = false;
// Can only use > and | if not wrapped in spaces or is not a key.
// Also, don't use if in flow mode.
if (spaceWrap || (state.flowLevel > -1 && state.flowLevel <= level)) {
if (spaceWrap) {
simple = false;
}
folded = false;
literal = false;
} else {
Expand Down
12 changes: 12 additions & 0 deletions test/issues/0235.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

var assert = require('assert');
var yaml = require('../../');

test('Flow style does not dump with block literals.', function () {
assert.strictEqual(yaml.dump({ a: '\n' }, { flowLevel: 0 }), '{a: "\\n"}\n');
});

test('Ok to dump block-style literals when not yet flowing.', function () {
assert.strictEqual(yaml.dump({ a: '\n' }, { flowLevel: 2 }), 'a: |\n\n');
});

0 comments on commit 8d06176

Please sign in to comment.