Skip to content

Commit aaee0e3

Browse files
committed
allow tabs when deciding about quoting
1 parent 0d3ca7a commit aaee0e3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/dumper.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ function isPrintable(c) {
199199
|| (0x10000 <= c && c <= 0x10FFFF);
200200
}
201201

202+
// Return true if the char is printable or a tab.
203+
// derived from nb-char - #x85 - #xA0 - #x2028 - #x2029.
204+
function isPrintableWithTabs(c) {
205+
return isPrintable(c) || c === CHAR_TAB;
206+
}
207+
202208
// [34] ns-char ::= nb-char - s-white
203209
// [27] nb-char ::= c-printable - b-char - c-byte-order-mark
204210
// [26] b-char ::= b-line-feed | b-carriage-return
@@ -332,7 +338,7 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth,
332338
// Check for disallowed characters to rule out plain and single.
333339
for (i = 0; i < string.length; char >= 0x10000 ? i += 2 : i++) {
334340
char = codePointAt(string, i);
335-
if (!isPrintable(char)) {
341+
if (!isPrintableWithTabs(char)) {
336342
return STYLE_DOUBLE;
337343
}
338344
plain = plain && isPlainSafe(char, prevChar, inblock);
@@ -352,7 +358,7 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth,
352358
string[previousLineBreak + 1] !== ' ');
353359
previousLineBreak = i;
354360
}
355-
} else if (!isPrintable(char)) {
361+
} else if (!isPrintableWithTabs(char)) {
356362
return STYLE_DOUBLE;
357363
}
358364
plain = plain && isPlainSafe(char, prevChar, inblock);

0 commit comments

Comments
 (0)