Skip to content

Commit

Permalink
Revert nodeca#470/nodeca#473 for dumper: too many situations where th…
Browse files Browse the repository at this point in the history
…e rendered output is ambiguous and hence erroneous YAML.
  • Loading branch information
GerHobbelt committed Apr 16, 2019
1 parent 587b02c commit 1da7558
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions lib/js-yaml/dumper.js
Expand Up @@ -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 = '"';
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 1da7558

Please sign in to comment.