Yes, you'd need to write \\ to insert a literal \. In general, I assume you'd expand the same escape sequences as these that are automatically expanded by the YAML parser for double-quoted scalars.

YAML parsers already handle quoted and unquoted scalars in different ways - this is part of the YAML spec (double-quoted vs. plain vs. literal vs. folded scalars). All YAML parsers must do this.

API-wise, you'd need to set up support for the binstr tag. We could add it to the official type repository as !!binstr.

Have fun,

    Oren Ben-Kiki

On Mon, Oct 31, 2011 at 11:14 PM, William Spitzak <> wrote:
I think this is an interesting idea, and did not realize that backslash was allowed outside quotes in YAML.

The big problem is that by not allowing quotes it also means the backslash sequence must be used for a lot of valid UTF-8 as well. Whitespace and quotes would have to be replaced with unreadable \xNN substitutes. All YAML delimiters would have to be replaced with unreadable substitutes unless the parser is altered so things like "\," are preserved. "\\" however would work, interestingly enough.

Interpreters will need to check if the input is quoted, not all YAML api's provide this. This is needed or just quoting would quadruple the number of backslashes and no error is produced by YAML if this is not done.

It may also be necessary to implement all YAML escapes such as "\b".

Oren Ben-Kiki wrote:
The YAML parser will only expand \x80 if it was inside double quotes. My example did not use double quotes:

 foo: !badstr BadName\x80

Which is different from:

 foo: !badstr "BadName\x80"