Skip to content

Commit 99c0bf9

Browse files
diberryVitaly Puzrin
authored and
Vitaly Puzrin
committed
Fix for issue #468 includes passing test (#469)
1 parent b6d2609 commit 99c0bf9

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/js-yaml/dumper.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ function writeNode(state, level, object, block, compact, iskey) {
735735
}
736736
}
737737
} else if (type === '[object Array]') {
738-
var arrayLevel = (state.noArrayIndent) ? level - 1 : level;
738+
var arrayLevel = (state.noArrayIndent && (level > 0)) ? level - 1 : level;
739739
if (block && (state.dump.length !== 0)) {
740740
writeBlockSequence(state, arrayLevel, state.dump, compact);
741741
if (duplicate) {

test/issues/0468.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
4+
var assert = require('assert');
5+
var yaml = require('../..');
6+
7+
test('should not indent arrays an extra level when disabled', function () {
8+
/* eslint-disable max-len */
9+
var output = yaml.dump(
10+
[
11+
{
12+
a: 'a_val',
13+
b: 'b_val'
14+
},
15+
{
16+
a: 'a2_val',
17+
items: [
18+
{
19+
a: 'a_a_val',
20+
b: 'a_b_val'
21+
}
22+
]
23+
}
24+
],
25+
{ noArrayIndent: true }
26+
);
27+
var expected = '- a: a_val\n b: b_val\n- a: a2_val\n items:\n - a: a_a_val\n b: a_b_val\n';
28+
assert.strictEqual(output, expected);
29+
});

0 commit comments

Comments
 (0)