After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 704528 - Scientific notation and leading whitespaces
Scientific notation and leading whitespaces
Status: RESOLVED FIXED
Product: libxml2
Classification: Platform
Component: general
2.4.26
Other Linux
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2013-07-19 08:25 UTC by Silvestre Abruzzo
Modified: 2013-07-22 05:25 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Silvestre Abruzzo 2013-07-19 08:25:42 UTC
$ cat testLarge.xml
<?xml version="1.0" encoding="utf-8"?>
<Refrigerator>
  <Apples>5000000000</Apples>
  <Bananas>10000000000000000</Bananas>
</Refrigerator>

$ cat testSmall.xml
<?xml version="1.0" encoding="utf-8"?>
<Refrigerator>
  <Apples>5</Apples>
  <Bananas>10</Bananas>
</Refrigerator>


$ cat collect.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="Refrigerator">
      <xsl:value-of select="Apples * Bananas" />
    </xsl:template>
</xsl:stylesheet>

$ xsltproc collect.xslt testLarge.xml
<?xml version="1.0"?>
 5e+25

$ xsltproc collect.xslt testSmall.xml
<?xml version="1.0"?>
50

The problem is that when I use testLarge.xml the
resulting value contains a leading whitespace, i.e. it is something
like " 5e+25". Instead, with small numbers I obtain "50" without
leading whitespace. The bug is not regarding the "extension" for the scientific notation but instead regarding the leading whitespace which is not consistent.

$ xsltproc --version
Using libxml 20900, libxslt 10127 and libexslt 816
xsltproc was compiled against libxml 20900, libxslt 10127 and libexslt 816
libxslt 10127 was compiled against libxml 20900
libexslt 816 was compiled against libxml 20900
Comment 1 Nick Wellnhofer 2013-07-21 15:09:55 UTC
$ xmllint empty.xml --xpath 'concat("val=", 2e12)'
val= 2e+12

Probably a bug in xmlXPathFormatNumber.
Comment 2 Daniel Veillard 2013-07-22 05:25:31 UTC
Yes I don't know why snprintf adds it:

2866			integer_place = DBL_DIG + EXPONENT_DIGITS + 1;
(gdb) 
2867			fraction_place = DBL_DIG - 1;
(gdb) 
2868			size = snprintf(work, sizeof(work),"%*.*e",
(gdb) 
2870			while ((size > 0) && (work[size] != 'e')) size--;
(gdb) p size
$1 = 21
(gdb) p work
$2 = " 2.", '0' <repeats 14 times>, "e+12\000\000\000\000\000\000\242"
(gdb) p integer_place
$3 = 21
(gdb) p fraction_place
$4 = 14
(gdb) p absolute_value
$5 = 2000000000000

  weird, simplest is to remove the leading spaces when they appear,
crude but effective little patch applied and pushed:

https://git.gnome.org/browse/libxml2/commit/?id=b9e4d5b6395f9aa0a34cb74e9a3672a20d37b943

  thanks !

Daniel