@@ -23,6 +23,9 @@ The syntax for scalars is similar to the PHP syntax.
2323Strings
2424~~~~~~~
2525
26+ Strings in YAML can be wrapped both in single and double quotes. In some cases,
27+ they can also be unquoted:
28+
2629.. code-block :: yaml
2730
2831 A string in YAML
@@ -31,26 +34,50 @@ Strings
3134
3235 ' A singled-quoted string in YAML'
3336
34- .. tip ::
37+ .. code-block :: yaml
3538
36- In a single quoted string, a single quote `` ' `` must be doubled:
39+ " A double- quoted string in YAML "
3740
38- .. code-block :: yaml
41+ Quoted styles are useful when a string starts or ends with one or more
42+ relevant spaces, because unquoted strings are trimmed on both ends when parsing
43+ their contents.
3944
40- ' A single quote '' in a single-quoted string'
45+ When using single-quoted strings, any single quote ``' `` inside its contents
46+ must be doubled to escape it:
4147
42- .. code-block :: yaml
48+ .. code-block :: yaml
4349
44- " A double -quoted string in YAML \n "
50+ ' A single quote '' inside a single -quoted string'
4551
46- Quoted styles are useful when a string starts or ends with one or more
47- relevant spaces.
52+ The double-quoted style provides a way to express arbitrary strings, by
53+ using ``\ `` escape sequences. It is very useful when you need to embed a
54+ ``\n `` or a Unicode character in a string.
55+
56+ .. code-block :: yaml
4857
49- .. tip ::
58+ " A double-quoted string in YAML \n "
5059
51- The double-quoted style provides a way to express arbitrary strings, by
52- using ``\ `` escape sequences. It is very useful when you need to embed a
53- ``\n `` or a unicode character in a string.
60+ If the string contains any of the following characters, it must be escaped with
61+ single quotes:
62+
63+ ===== ===== ===== ===== =====
64+ ``: `` ``{ `` ``} `` ``[ `` ``] ``
65+ ``, `` ``& `` ``* `` ``# `` ``? ``
66+ ``| `` ``- `` ``< `` ``> `` ``= ``
67+ ``! `` ``% `` ``@ `` ``\` ``
68+ ===== ===== ===== ===== =====
69+
70+ If the string contains any of the following control characters, it must be
71+ escaped with double quotes. In addition, the escaping must use a double slash
72+ ``\\ `` to avoid parsing issues:
73+
74+ ======== ======== ======== ======== ======== ======== ======== ========
75+ ``\0 `` ``\x01 `` ``\x02 `` ``\x03 `` ``\x04 `` ``\x05 `` ``\x06 `` ``\a ``
76+ ``\b `` ``\t `` ``\n `` ``\v `` ``\f `` ``\r `` ``\x0e `` ``\x0f ``
77+ ``\x10 `` ``\x11 `` ``\x12 `` ``\x13 `` ``\x14 `` ``\x15 `` ``\x16 `` ``\x17 ``
78+ ``\x18 `` ``\x19 `` ``\x1a `` ``\e `` ``\x1c `` ``\x1d `` ``\x1e `` ``\x1f ``
79+ ``\N `` ``\_ `` ``\L `` ``\P ``
80+ ======== ======== ======== ======== ======== ======== ======== ========
5481
5582When a string contains line breaks, you can use the literal style, indicated
5683by the pipe (``| ``), to indicate that the string will span several lines. In
0 commit comments