[llvm] r205839 - YAMLIO: Encode ambiguous hex strings explicitly

David Majnemer david.majnemer at gmail.com
Wed Apr 9 10:16:57 PDT 2014


YAML 1.1 has just zero as an octal prefix:
http://www.yaml.org/spec/1.1/#id858600

This seems to be the behavior of the most popular YAML readers I can get my
hands on:
irb(main):002:0> YAML.load("010")
=> 8

>>> yaml.load("010")
8


We get the distinction between strings and integers wrong without this
change.  It's pretty easy to see this if you serialize a StringRef holding
a decimal (like "3") or hexadecimal number (like "0x3"), we will write it
out unquoted which turns it into a number.

On Wed Apr 09 2014 at 7:50:30 AM, Michael Spencer <bigcheesegs at gmail.com>
wrote:

> On Wed, Apr 9, 2014 at 8:56 AM, David Majnemer <david.majnemer at gmail.com>
> wrote:
> > Author: majnemer
> > Date: Wed Apr  9 02:56:27 2014
> > New Revision: 205839
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=205839&view=rev
> > Log:
> > YAMLIO: Encode ambiguous hex strings explicitly
> >
> > YAMLIO would turn a BinaryRef into the string 0000000004000000.
> > However, the leading zero causes parsers to interpret it as being an
> > octal number instead of a hexadecimal one.
> >
> > Instead, escape such strings as needed.
> >
>
> This is wrong. In YAML all numbers are treated as decimal. Also this
> changes the tag type of the value to !!str.
>
> The correct change is to fix the reader to always do decimal and
> handle the 0x and 0o prefixes.
>
> See: http://www.yaml.org/spec/1.2/spec.html#id2805071
>
> - Michael Spencer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140409/3b3785e7/attachment.html>


More information about the llvm-commits mailing list