QuickLib icon indicating copy to clipboard operation
QuickLib copied to clipboard

YAML parser does not support escape sequences (e.g. "\u0000")

Open dougwinsby opened this issue 3 years ago • 0 comments

There does not appear to be any way to encode a double quote (") scalar value (or any special character) with this library.

The YAML specification allows special characters to be escaped in double-quoted scalar values.

Also, to escape a double quote, you should be able to include it in a single-quoted string:

'"'

But YAML also supports unicode hex characters using:

"\u0022"

If this library supported just this second method, any unicode character could be included (including a double quote).

For those looking for a work-around, we used a JSON parser from the Synopse (mORMot) library. The SynCommons.pas file is all you need. Here is an example of how it would work:

uses
  SynCommons;

function DecodeEscapeSequences(const s: string): string;
begin
  if s.Contains('\u') then
  begin
    var v := _json('{value:"' + RawUTF8(s) + '"}');
    result := v.value;
    Exit;
  end;
  result := s;
end;

Any JSON parser would probably work because the JSON standard supports these escape sequences.

dougwinsby avatar Dec 19 '22 16:12 dougwinsby