chyh1990 / yaml-rust

A pure rust YAML implementation.
Apache License 2.0
611 stars 140 forks source link

Add `escape_all_strings` option to `Emitter` #129

Open paulhauner opened 5 years ago

paulhauner commented 5 years ago

First of all, thanks for this library. It's been great and has got me out of some sticky situations where serde is not flexible enough. Much appreciated.

This PR makes a change to ensure typing between loading and emitting.

Problem

Consider the following YAML:

example: "0x00"

After one round of YamlLoader -> YamlEmitter the YAML is now:

example: 0x00

After a second round the YAML is then:

example: 0

The YAML has now changed significantly and information has been lost.

Solution

I added an emitter.escape_all_strings(bool) function which forces all YAML::String nodes to be wrapped in double-quotes.

I would be interested on your opinion on two points:

Thank you for you time, happy to make changes as you require.