[xml/sgml-pkgs] Bug#279926: libxslt1.1: date:week-in-month() bugginess
Sal Paradise
"Sal Paradise" <m2kyj0402@sneakemail.com>, 279926@bugs.debian.org
5 Nov 2004 23:16:20 -0000
Package: libxslt1.1
Version: 1.1.8-5
Severity: normal
Tags: patch
The EXSLT function date:week-in-month() produces bad values on some
inputs described here. Apply the following stylesheet to any XML document
(the XML input is ignored) using xsltproc to reproduce.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times" version="1.0">
<xsl:output method="text"/>
<xsl:variable name="nl">
<xsl:text>
</xsl:text>
</xsl:variable>
<xsl:template match="/">
<xsl:variable name="mydate" select="'2000-10-01T08:26:10Z'"/>
<xsl:value-of select="date:week-in-month($mydate)"/>
<xsl:value-of select="$nl"/>
</xsl:template>
</xsl:stylesheet>
The buggy output from libxslt1.1 is:
2
The correct output should be:
1
Here is another stylesheet with bad output:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times" version="1.0">
<xsl:output method="text"/>
<xsl:variable name="nl">
<xsl:text>
</xsl:text>
</xsl:variable>
<xsl:template match="/">
<xsl:variable name="mydate" select="'2000-10-08T08:26:10Z'"/>
<xsl:value-of select="date:week-in-month($mydate)"/>
<xsl:value-of select="$nl"/>
</xsl:template>
</xsl:stylesheet>
The buggy output from libxslt1.1 is:
3
The correct output should be:
2
For an explanation of why, read the spec of this function carefully at:
http://www.exslt.org/date/functions/week-in-month/index.html
Here is a patch that fixes the problem:
--- libxslt-1.1.8/libexslt/date.c 2004-05-16 23:25:26.000000000 -0400
+++ libxslt-1.1.8-fixed/libexslt/date.c 2004-11-05 18:04:21.000000000 -0500
@@ -2141,7 +2141,7 @@
*/
fdiw = (_exsltDateDayInWeek(fdiy, dt->value.date.year) + 6) % 7;
- ret = ((dt->value.date.day + fdiw) / 7) + 1;
+ ret = ((dt->value.date.day + fdiw - 1) / 7) + 1;
exsltDateFreeDate(dt);
Note that this bug still exists in the latest upstream version (1.1.12) too,
so the patch should be forwarded upstream.
-- System Information:
Debian Release: 3.1
APT prefers unstable
APT policy: (500, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.6.7
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Versions of packages libxslt1.1 depends on:
ii libc6 2.3.2.ds1-18 GNU C Library: Shared libraries an
ii libgcrypt11 1.2.0-10 LGPL Crypto library - runtime libr
ii libgpg-error0 1.0-1 library for common error values an
ii libxml2 2.6.11-5 GNOME XML library
ii zlib1g 1:1.2.2-3 compression library - runtime
-- no debconf information