# To quote or not to quote (I think it's a bug)

**URL:** <https://www.ruby-forum.com/t/to-quote-or-not-to-quote-i-think-its-a-bug/86121>\
**Category:** Ruby\
**Created:** [February 20, 2007, 2:04am UTC](https://www.ruby-forum.com/t/to-quote-or-not-to-quote-i-think-its-a-bug/86121 "2007-02-20T02:04:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthieu\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@Matthieu\_R](https://www.ruby-forum.com/u/Matthieu_R)\
**Post date:** [February 20, 2007, 2:04am UTC](https://www.ruby-forum.com/t/to-quote-or-not-to-quote-i-think-its-a-bug/86121/1 "2007-02-20T02:04:20Z")

</div>

Hi,

I’m not sure this is the right place to report issues about Syck but  
that’s  
the best I’ve found so far 🙂 I think I’ve found a problem with the way  
Syck  
quotes strings that could look like floats. Here is a short example:

irb(main):001:0\> require ‘yaml’  
=\> true  
irb(main):002:0\> YAML.dump([“1.2”, “1.2.3”, “1.2\_3”])  
=\> “— \n- “1.2”\n- 1.2.3\n- 1.2\_3\n”

The first element is quoted appropriately, the second isn’t because  
there’s  
no ambiguity but the third should be quoted. The YAML float can have  
underscores, they’re used as visual separators and should be ignored by  
the  
parser. So when seeing 1.2\_3 the parser should read the float 1.23. Then  
to  
disambiguates the string “1.2\_3” should be quoted.

Practically this isn’t really a problem as YAML converts on writes so  
YAML.dump(1.2\_3) gets directly written as 1.23. However it creates some  
interoperability issues when “1.2\_3” gest written unquoted by Syck and  
then  
read by another parser as being 1.23. The string isn’t a string anymore  
in  
that case.

What do you think?

Thanks,  
Matthieu R.

---

<div class="post-metadata">

**Author:** ![Matthieu\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@Matthieu\_R](https://www.ruby-forum.com/u/Matthieu_R)\
**Post date:** [February 20, 2007, 5:13am UTC](https://www.ruby-forum.com/t/to-quote-or-not-to-quote-i-think-its-a-bug/86121/2 "2007-02-20T05:13:30Z")

</div>

On 2/19/07, Matthieu R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> that case.

Are you certain that 1.2\_3 is a valid YAML float?

[http://yaml.org/type/float.html](http://yaml.org/type/float.html)

I do not believe underscores are valid in either YAML floats or YAML  
integers. Although they are allowed in Ruby, I believe Syck is  
handling your example case properly and without ambiguity.

Blessings,  
TwP

---

<div class="post-metadata">

**Author:** ![Matthieu\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@Matthieu\_R](https://www.ruby-forum.com/u/Matthieu_R)\
**Post date:** [February 20, 2007, 5:28am UTC](https://www.ruby-forum.com/t/to-quote-or-not-to-quote-i-think-its-a-bug/86121/3 "2007-02-20T05:28:30Z")

</div>

Hi Tim,

In that page:

“Any “_\__” characters in the number are ignored, allowing a readable  
representation of large values.”

So clearly they’re allowed, in 1.2\_3 the underscore is simply ignored  
and  
the parser should undestand 1.23. If I fancy to write my own YAML by  
hand  
and make it easily readable (which is kind of the original purpose) I  
could  
write 100\_000\_000.03 which would be a nice looking float. Hence the  
ambiguity with “1.2\_3”.

Cheers,  
Matthieu

---

<div class="post-metadata">

**Author:** ![Matthieu\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@Matthieu\_R](https://www.ruby-forum.com/u/Matthieu_R)\
**Post date:** [February 20, 2007, 6:13am UTC](https://www.ruby-forum.com/t/to-quote-or-not-to-quote-i-think-its-a-bug/86121/4 "2007-02-20T06:13:33Z")

</div>

> ambiguity with “1.2\_3”.  
> But the specification is not just in english, it’s also in regex form:

[-+]?([0-9][0-9\_]_)?.[0-9.]_([eE][-+][0-9]+)? (base 10)  
|[-+]?[0-9][0-9\_]_(:[0-5]?[0-9])+.[0-9\_]_ (base 60)  
|[-+]?.(inf|Inf|INF) # (infinity)  
|.(nan|NaN|NAN) # (not a number)

For a base 10 number, underscores are permitted only if they appear  
BEFORE the decimal point, so for 1.2\_3 there is no ambiguity.

Dan.

---

<div class="post-metadata">

**Author:** ![Matthieu\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@Matthieu\_R](https://www.ruby-forum.com/u/Matthieu_R)\
**Post date:** [February 20, 2007, 6:25am UTC](https://www.ruby-forum.com/t/to-quote-or-not-to-quote-i-think-its-a-bug/86121/5 "2007-02-20T06:25:33Z")

</div>

> So clearly they’re allowed, in 1.2\_3 the underscore is simply  
> ignored and  
> the parser should undestand 1.23. If I fancy to write my own  
> YAML by hand  
> and make it easily readable (which is kind of the original  
> purpose) I could  
> write 100\_000\_000.03 which would be a nice looking float. Hence the  
> ambiguity with “1.2\_3”

Hmmmm… I just noticed that the specification  
([Floating-Point Language-Independent Type for YAML™&nbsp;Version&nbsp;1.1](http://yaml.org/type/float.html)) isn’t just unclear, it’s inconsistent.

The examples listed include:

exponentioal: 685.230\_15e+03

Notwithstanding the spelling of exponential, that example is not  
consistent with the regular expression (which allows underscores only if  
they preceed the decimal point -  
[-+]?([0-9][0-9\_]_)?.[0-9.]_([eE][-+][0-9]+)?).

Dan.

---

<div class="post-metadata">

**Author:** ![Matthieu\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3bc359/32.png) [@Matthieu\_R](https://www.ruby-forum.com/u/Matthieu_R)\
**Post date:** [February 20, 2007, 7:16am UTC](https://www.ruby-forum.com/t/to-quote-or-not-to-quote-i-think-its-a-bug/86121/6 "2007-02-20T07:16:37Z")

</div>

On Tue, Feb 20, 2007 at 10:03:25AM +0900, Matthieu R. wrote:

> The first element is quoted appropriately, the second isn’t because there’s  
> no ambiguity but the third should be quoted. The YAML float can have  
> underscores, they’re used as visual separators and should be ignored by the  
> parser.

Only in YAML 1.1. Syck only speaks YAML 1.0. Unfortunately, the  
types repository for 1.0 is no longer at [yaml.org](http://yaml.org).

See [Float Language-Independent Type For YAML](http://web.archive.org/web/20030815095109/yaml.org/type/float/)  
for the floats which Syck should support.

\_why
