ruby / psych

A libyaml wrapper for Ruby
MIT License
564 stars 201 forks source link

Prevent snakeYAML add backslash when dump multiple line string #642

Open yvesll opened 1 year ago

yvesll commented 1 year ago

Given the following input

key:
  "/Psych is a YAML parser and emitter. Psych leverages libyaml 
  for its YAML parsing and emitting capabilities. In addition to wrapping 
  libyaml, Psych also knows how to serialize and de-serialize most Ruby 
  objects to and from the YAML format./"
empty_key:

Then load and dump it: Within MRI ruby, the output is:

---
key: "/Psych is a YAML parser and emitter. Psych leverages libyaml for its YAML parsing
  and emitting capabilities. In addition to wrapping libyaml, Psych also knows how
  to serialize and de-serialize most Ruby objects to and from the YAML format./"
empty_key: #An empty space was added here.

But in jruby, the result is a little different:

---
key: "/Psych is a YAML parser and emitter. Psych leverages libyaml for its YAML parsing\
  \ and emitting capabilities. In addition to wrapping libyaml, Psych also knows how\
  \ to serialize and de-serialize most Ruby objects to and from the YAML format./"
empty_key:

There are two differences:

  1. Jruby added backslashes for new line
  2. MRI ruby added a space after empty_key:
headius commented 12 months ago

Could this be something that changed in YAML 1.2? The Psych extension for JRuby moved to a newer version of SnakeYAML (SnakeYAML Engine) that is now YAML 1.2 compliant.