Re: [xml] "double"s and schema validation



On Wed, Jul 21, 2010 at 14:23, Csaba Raduly <rcsaba gmail com> wrote:
On Tue, Jul 20, 2010 at 3:40 AM, Dan Sommers  wrote:
Given this schema file, t.xsd:

   <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";>
     <xs:element name="t" type="xs:double"/>
   </xs:schema>

And this xml document, t.xml:

   <t>e</t>

I got this:

   $ xmllint --schema t.xsd t.xml
   <?xml version="1.0"?>
   <t>e</t>
   t.xml validates

Note that <t>.</t> and <t>.e</t> also validate.

I tracked it down to xmlschematypes.c, starting around line 2465, where
it starts scanning the input for something suitable for sscanf("%lf").
Should that code contain an extra check that there is at least one digit
somewhere?

I think you are right. This code:
               while ((*cur >= '0') && (*cur <= '9')) {
                   cur++;
               }
accepts 0 or more digits (before the period); perhaps it should check
for 1 or more digits instead:

No!  The case like ".5" instead of "0.5" is perfectly valid and widely used!
Whether the "." or "e" are valid string representation of the "double"
type or should be rejected -- it's another matter.  But zero digits
before dot are absolutely correct and should be allowed.

-- 
Andrew W. Nosenko <andrew w nosenko gmail com>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]