Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do Unicode escaping in YAML multiline string?

Tags:

yaml

unicode

Is it possible to use Unicode character escaping (e.g. \u2009) in YAML multiline strings?

this_escape_works: "foo\u2009bar"
this_escape_doesnt: >
  foo\u2009bar
like image 416
Sampo Avatar asked Mar 02 '16 11:03

Sampo


1 Answers

As per the YAML1.2 spec double quoted style for scalars is:

the only style capable of expressing arbitrary strings, by using “\” escape sequences. This comes at the cost of having to escape the “\” and “"” characters.

So folded scalars do not support escaping and you have to do

this_escape_works: "foo\u2009bar"
this_escape_doesnt: "foo\u2009bar\n"

Please note that contrary to @nj_'s claim the folding indicator > (it is not an operator) doesn't do "newlines become spaces" in general and certainly not for the final line break

like image 198
Anthon Avatar answered Oct 13 '22 14:10

Anthon