Re: Possible bug with null document in libyaml

Ingy dot Net <[email protected]>
Newsgroups gmane.text.yaml.general
Message-ID <[email protected]>
On Fri, Nov 20, 2009 at 1:11 PM, William Spitzak <[email protected]> wrote:

> libyaml treats a file containing nothing but zero or more newlines as
> being completely empty and parses nothing out of it. However this
> appears to be inconsistent:
>
> The text "---\nx\n..." and "x" produce the same result: a start, "x"
> scalar, and an end token.
>
> But the text "---\n\n..." and "" produce different results. The first
> produces start, a "" scalar, and an end. The second produces nothing.
>
> In addition writing a single "" scalar using libyaml without the
> document start/end produces a file containing only a newline and thus is
> not inverted by the parser.
>
> This may seem trivial but I am using yaml internally to store serialized
> values of small pieces of data, and blank strings were breaking because
> of this. I had to modify libyaml to quote zero-length strings but I do
> not think that is the desired solution.
>
> My recommendation is that a completely blank yaml file be parsed as a
> single "" scalar. This may seem dangerous, because this file will
> "vanish" if concatenated with other data, but concatenation is not
> supposed to work anyway if the surrounding "---" and "..." are missing.
>
> Any opinions or have I missed anything?
>

It has always been the intent of YAML, that a Stream may contain zero or
more Documents. This implies that there needs to be a way to serialize zero
objects.

BTW, a stream containing just comments is another example of something that
will parse as having zero documents.

It may not be written like this in the spec, but one way to think of it is
as follows:

   1. Every YAML Document in a YAML Stream begins with '---'.
   2. If the first thing a parser sees in a stream, after skipping all
   ignorable whitespace (including comments), is not '---', nor a YAML
   directive, the parser should assume it saw "---\n".
   3. If, after skipping all ignorable whitespace, the parser reaches the
   End Of Stream, it should report an STREAM_END event, without reporting any
   documents.

Being able to serialize zero documents is important. For a real use case,
imagine a service listening for YAML documents over a web socket. If the
socket is closed after receiving no data, the service should *not* parse
that as one document containing an empty string.

After testing all these cases against libyaml, IMHO it gets things right
every time.

Cheers, Ingy


> Thanks
> Bill Spitzak
> Rhythm & Hues software department.
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Yaml-core mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/yaml-core
>

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july

_______________________________________________
Yaml-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/yaml-core
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.