safeDump automatically reformat yaml strings
See original GitHub issueI have question regarding the behavior of js-yaml with safeDump, we have a yaml editor which use the following method to generate yaml from js object:
self.generateYAML = function (graph) {
if (graph === undefined) {
return '';
}
try {
return jsyaml.safeDump(graph, {
noCompatMode: true // fix auto quoting 'y'.
}).trim();
} catch (e) {
var error = 'YAML validation error: ' + e.message;
console.log(error);
return '';
}
};
graph is passed with an object that has the following content:
'Fn::Base64':
'Fn::Join':
- "\n"
-
- scriptFile=~/createSchema.sh
- scriptLog=~/createSchema.log
- rm -f ${scriptFile}
- touch ${scriptFile}
- touch ${scriptLog}
- echo "sqlplus / as sysdba << EOF" >> ${scriptFile}
- echo "drop user c##myappuser cascade;" >> ${scriptFile}
- echo "create user c##myappuser identified by ${schemaPassword};" >> ${scriptFile}
- echo "grant create session, create table, unlimited tablespace to c##myappuser;" >> ${scriptFile}
- echo "quit" >> ${scriptFile}
- echo "EOF" >> ${scriptFile}
- sh ${scriptFile} >> ${scriptLog}
Somehow after safedump, the line break was reformated (though it’s still correct) and yaml becomes the following
The version we used is 3.10.0. Please let me know if there’s anything I can do to disable this automatic transformation. Thanks.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
yaml.dump adding unwanted newlines in multiline strings
My real problem is that if humans read this YAML file they will probably assume, as I did, that my program has broken...
Read more >nodeca/js-yaml: JavaScript YAML parser and dumper. Very fast.
Parses string as single YAML document. Returns either a plain object, a string, a number, null or undefined , or throws YAMLException on...
Read more >PyYAML Documentation
# A Python object corresponding to the document. If a string or a file contains several documents, you may load them all with...
Read more >How to use safeDump function in js-yaml - Javascript - Tabnine
Writes a configuration file in YAML format. * @param {Object} config The configuration object to write. * @param {string} filePath The filename to...
Read more >The YAML Format (Symfony Docs)
Strings in YAML can be wrapped both in single and double quotes. ... 2014-12-31 ) (otherwise it would be automatically converted into a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
https://github.com/nodeca/js-yaml#safedump-object---options-
set
lineWidth
toInfinity
I just realized it’s not an issue with safeDump but probably the way safeLoad works. For template that contains
"\n"
, it will be converted to enter key, but for'\n'
it will be treated as"\\n"
, and I just took a look here http://docs.octoprint.org/en/master/configuration/yaml.html. Seems like the behavior is correct on js-yaml. Thanks for helping. The template user provides is invalid in our case here.