Closed
Description
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
Line 294 in b6d2609
Lines 192 to 205 in b6d2609
All of these characters ( except0xFEFF
) are safe inside string. Only colon cannot be followed by space or placed at the end of line.
Activity
diberry commentedon Feb 26, 2019
This is the same as #466. Perhaps we can have a new setting to handle the quoting issue?
puzrin commentedon Feb 26, 2019
@joshuaavalon "unquoting" quality is limited only by authors time. If anyone has time to improve it - PR is welcome.
diberry commentedon Feb 26, 2019
@puzrin I'll make a PR this weekend, if no one does it before then.
diberry commentedon Mar 2, 2019
PR 454 seems related
diberry commentedon Mar 3, 2019
@puzrin Are these tests all valid/correct?
`test.only('should not unnecessaryly apply quotes', function () {
var expected = 'url: https://github.com/nodeca/js-yaml\n';
var actual = yaml.dump({ url: 'https://github.com/nodeca/js-yaml' });
assert.strictEqual(actual, expected);
});
test.only('should not unnecessaryly apply quotes - ', function () {
var expected = 'url: https://github.com/nodeca/js-yaml\n';
var obj = {};
obj['url']='https://github.com/nodeca/js-yaml';
var actual = yaml.dump(obj);
assert.strictEqual(actual, expected);
});
test.only('should not unnecessaryly apply quotes - space then /\n at end of value', function () {
var expected = 'url: 'https://github.com/nodeca/js-yaml '\n';
var obj = {};
obj['url']='https://github.com/nodeca/js-yaml ';
var actual = yaml.dump(obj);
assert.strictEqual(actual, expected);
});
test.only('should not unnecessaryly apply quotes - space after colon', function () {
var expected = 'url: 'https: //github.com/nodeca/js-yaml'\n';
var actual = yaml.dump({ url: 'https: //github.com/nodeca/js-yaml' });
assert.strictEqual(actual, expected);
});
`
puzrin commentedon Mar 3, 2019
Could you format you message and add proper lang type for highlight?
spelling correction for nodeca#470 test descriptions
extended tests for nodeca#470, including bugfix for the dumper: now a…
extended tests for nodeca#470, including bugfix for the dumper: now a…
spelling correction for nodeca#470 test descriptions
Revert nodeca#470/nodeca#473 for dumper: too many situations where th…
fixups following the nodeca#470/nodeca#473 revert action.
kchen-shanghai commentedon Jul 2, 2020
Having a same problem here. Since only colon and hash characters are limited in flow scalars, is a PR still welcome by now?
Giszmo commentedon Jul 22, 2020
@ZEROPC I would appreciate a fix but but not speaking for the project. Crossing fingers :D
27 remaining items