From 1da7558d6e33666c768895cbc27e62d0f15e444d Mon Sep 17 00:00:00 2001 From: Ger Hobbelt Date: Tue, 16 Apr 2019 20:34:43 +0200 Subject: [PATCH] Revert #470/#473 for dumper: too many situations where the rendered output is ambiguous and hence erroneous YAML. --- lib/js-yaml/dumper.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/js-yaml/dumper.js b/lib/js-yaml/dumper.js index f136f210..eac5e62d 100644 --- a/lib/js-yaml/dumper.js +++ b/lib/js-yaml/dumper.js @@ -117,9 +117,9 @@ function State(options) { this.noCompatMode = options['noCompatMode'] || false; this.condenseFlow = options['condenseFlow'] || false; this.scalarQuoteStyle = options['scalarQuoteStyle'] || null; - this.forceSeqFlow = options['forceSeqFlow'] || false; + this.forceSeqFlow = options['forceSeqFlow'] || false; // accept a `quoteKeys` option *explicitly* set to FALSE: - this.quoteKeys = (options['quoteKeys'] != null ? options['quoteKeys'] : !!this.condenseFlow); + this.quoteKeys = (options['quoteKeys'] != null ? options['quoteKeys'] : !!this.condenseFlow); if (this.quoteKeys) { if (this.quoteKeys === true) { this.quoteKeys = '"'; @@ -201,7 +201,18 @@ function isPrintable(c) { // Simplified test for values allowed after the first character in plain style. function isPlainSafe(c) { - return isPrintable(c) && c !== 0xFEFF; + // Uses a subset of nb-char - c-flow-indicator - ":" - "#" + // where nb-char ::= c-printable - b-char - c-byte-order-mark. + return isPrintable(c) && c !== 0xFEFF + // - c-flow-indicator + && c !== CHAR_COMMA + && c !== CHAR_LEFT_SQUARE_BRACKET + && c !== CHAR_RIGHT_SQUARE_BRACKET + && c !== CHAR_LEFT_CURLY_BRACKET + && c !== CHAR_RIGHT_CURLY_BRACKET + // - ":" - "#" + && c !== CHAR_COLON + && c !== CHAR_SHARP; } // Simplified test for values allowed as the first character in plain style. @@ -265,9 +276,7 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, te var shouldTrackWidth = lineWidth !== -1; var previousLineBreak = -1; // count the first line correctly var plain = isPlainSafeFirst(string.charCodeAt(0)) - && !isWhitespace(string.charCodeAt(string.length - 1)) - && /\s#/.test(string) === false - && /:(?:\s|$)/.test(string) === false; + && !isWhitespace(string.charCodeAt(string.length - 1)); if (singleLineOnly) { // Case: no block styles. @@ -301,7 +310,7 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, te // in case the end is missing a \n hasFoldableLine = hasFoldableLine || (shouldTrackWidth && (i - previousLineBreak - 1 > lineWidth && - string[previousLineBreak + 1] !== ' ')); + string[previousLineBreak + 1] !== ' ')); } // Although every style can represent \n without escaping, prefer block styles // for multiline, since they're more readable and they don't add empty lines.