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 569703 - libexslt str:replace is non-conformant
libexslt str:replace is non-conformant
Status: RESOLVED FIXED
Product: libxslt
Classification: Platform
Component: general
1.1.22
Other All
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2009-01-29 17:38 UTC by Ron Burk
Modified: 2012-09-04 06:57 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Rewrite of str:replace (11.99 KB, patch)
2010-07-06 23:21 UTC, Nick Wellnhofer
none Details | Review

Description Ron Burk 2009-01-29 17:38:24 UTC
Please describe the problem:
The libexslt implementation of str:replace fails to conform to its specification on several counts:

a) the current version returns a string; it's supposed to
   return a nodeset.

b) the current version treats the replacements as strings;
   it's supposed to treat them as nodes.

c) the current version can modify replacement text; it's
   supposed to only modify text from the original string.

d) the current version ignores the requirement to perform
   substitutions in descending order of search string length.


Steps to reproduce:
a) the returning of a string rather than a nodeset can be seen
   by simply inspecting the code.

b) the code explicity converts replacement nodes to strings;
   this can be seen by inspection.
d) the failure to perform substitutions in descending order
   of search string length can be seen in the lack of any
   sorting in the source code.

c) the problem of modifying text not belonging to the original
   string can be seen in the following stylesheet, which can
   be simply applied to itself to produce output.

<xsl:stylesheet version="1.0"
    extension-element-prefixes="str exsl"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:exsl="http://exslt.org/common"
    xmlns:str="http://exslt.org/strings"
    >
<xsl:variable name="Text">
    Price is $1.10
</xsl:variable>

<xsl:template match="/">
    <xsl:apply-templates select="exsl:node-set($Text)/text()"/>
</xsl:template>
<xsl:template match="text()">
   <xsl:variable name="Replace">
        <FromXml>
            <from>$</from>
            <from>\</from>
        </FromXml>
        <ToTex>
            <to>\$</to>
            <to>$\backslash$</to>
        </ToTex>
    </xsl:variable>
    <xsl:value-of
        select="str:replace(.,exsl:node-set($Replace)/FromXml/from,exsl:node-set($Replace)/ToTex/to)"/>
</xsl:template>
</xsl:stylesheet>


Actual results:
The output is:

<?xml version="1.0"?>

    Price is $\backslash$$1.10


Expected results:
The output should be:
<?xml version="1.0"?>

    Price is \$1.10


Does this happen every time?
yes.

Other information:
str:replace specification is at:

http://www.exslt.org/str/functions/replace/str.replace.html
Comment 1 Nick Wellnhofer 2010-07-06 23:20:43 UTC
See the following patch for a complete rewrite of str:replace that should address all your issues.
Comment 2 Nick Wellnhofer 2010-07-06 23:21:26 UTC
Created attachment 165389 [details] [review]
Rewrite of str:replace
Comment 3 Daniel Veillard 2012-09-04 06:57:04 UTC
Never too late I suppose, looks good, I'm pushing your updated version

  thanks !

Daniel