Dumping add quote to string even it is not necessary (original) (raw)
As title.
Test Code
const jsYaml = require("js-yaml"); const fs = require("fs"); const yamlStr = jsYaml.dump({ url: "https://github.com/nodeca/js-yaml" }); fs.writeFileSync("foo.yml", yamlStr, { encoding: "utf8" });
Expected Result
url: https://github.com/nodeca/js-yaml
Actual Result
url: 'https://github.com/nodeca/js-yaml'
Problem
| plain = plain && isPlainSafe(char); |
|---|
| function isPlainSafe(c) { |
|---|
| // 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; |
| } |
All of these characters ( except0xFEFF ) are safe inside string. Only colon cannot be followed by space or placed at the end of line.