Re: [xml] libxml2 version 2.9.0: xpath.c:xmlXPathStringEvalNumber() - not 100% fails to parse float with leading '+'

On Mon, May 06, 2013 at 12:41:22PM +0000, Kuhnke, Christoph (I/EF-56, extern) wrote:
Dear creators of libxml2, 


 might be better to subscribe to the list so i don't have to dig your
messages in the mailing-list bounces, which I tend to forget doing !

I think I found a slight mistake in function xpath.c:xmlXPathStringEvalNumber()
of libxml2 version 2.9.0.

For data type "float" in xml files resp. xml schemas 
[1] states "The mantissa must be a decimal number."
[2] contains details: 
      An optional leading sign is allowed. 
      If the sign is omitted, "+" is assumed. 
and names "+100000.00" as valid example for a decimal.

In contrast when first non-whitespace-character of it's argument is a '+',
xpath.c:xmlXPathStringEvalNumber() stops parsing and return 0.0.

To make libxml2 conform to [1] I suggest the following change:

Replace 3 lines 10098 through 10100 (incl.) 
by the following 7 lines 

    if ((*cur != '.') && ((*cur < '0') || (*cur > '9')) && (*cur != '-') && (*cur != '+')) {
    if (*cur == '+') {
      isneg = 0;

Please let me know, what you think about my proposal.

[1] Lexical representation
[2] Lexical representation

  Ah well I am sorry but that's the wrong reference ;-)
Surprizingly enough xpath.c:xmlXPathStringEvalNumber() is part of the
implementation of XPath (version 1),

 "a string that consists of optional whitespace followed by an optional
 minus sign followed by a Number followed by whitespace is converted to
 the IEEE 754 number that is nearest (according to the IEEE 754
 round-to-nearest rule) to the mathematical value represented by the
 string; any other string is converted to NaN"

[30]    Number     ::=      Digits ('.' Digits?)?
                      | '.' Digits
[31]    Digits     ::=  [0-9]+

 basically no "+" is allowed by XPath 1 for the beginning of numbers
so the function is I think correct.
 Libxml2 actually has a xml Schemas (version 1) datatype implementation
and it does check float values, the code is in
  xmlSchemaValAtomicType() in xmlschemastypes.c
see around line 2393, it does accept a leading "+"

  It's a feature, not a bug, at least at the libxml2 level, at the
W3C spec level it is a slight incoherence...


Daniel Veillard      | Open Source and Standards, Red Hat
veillard redhat com  | libxml Gnome XML XSLT toolkit | virtualization library

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