diff options
author | Nick Wellnhofer <wellnhofer@aevum.de> | 2012-09-04 14:38:06 +0800 |
---|---|---|
committer | Daniel Veillard <veillard@redhat.com> | 2012-09-04 14:38:06 +0800 |
commit | 0602c535e9c34efca22dba1b1b7465e0618e7bfc (patch) | |
tree | 283ce2e4e5da6db29b4494fdfaf7241e52bccbf2 /tests/exslt | |
parent | 39b0c27af8a18e38b95bf50c40767610d8a13906 (diff) | |
download | libxslt-0602c535e9c34efca22dba1b1b7465e0618e7bfc.tar.gz libxslt-0602c535e9c34efca22dba1b1b7465e0618e7bfc.tar.bz2 libxslt-0602c535e9c34efca22dba1b1b7465e0618e7bfc.zip |
Rewrite EXSLT string:replace to be conformant
For https://bugzilla.gnome.org/show_bug.cgi?id=569703
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
Diffstat (limited to 'tests/exslt')
-rw-r--r-- | tests/exslt/strings/replace.1.out | 12 | ||||
-rw-r--r-- | tests/exslt/strings/replace.1.xml | 4 | ||||
-rw-r--r-- | tests/exslt/strings/replace.1.xsl | 13 |
3 files changed, 28 insertions, 1 deletions
diff --git a/tests/exslt/strings/replace.1.out b/tests/exslt/strings/replace.1.out index 076d1101..f41d67cc 100644 --- a/tests/exslt/strings/replace.1.out +++ b/tests/exslt/strings/replace.1.out @@ -1,5 +1,9 @@ <?xml version="1.0"?> <out>; + result nodes: 1 + result text nodes: 1 + result string: a + str:replace('a, simple, list', ', ', '-') a-simple-list @@ -19,4 +23,10 @@ tee, eye, billow, a longer string str:replace('fee, fi, fo, fum', $x, 'j') - j, j, j, j</out> + j, , , + + str:replace('foo', '', 'baz') + fbazobazo + + str:replace('Price is $1.10', $from, $to) + Price is \$1.10</out> diff --git a/tests/exslt/strings/replace.1.xml b/tests/exslt/strings/replace.1.xml index 6371161f..16aac14c 100644 --- a/tests/exslt/strings/replace.1.xml +++ b/tests/exslt/strings/replace.1.xml @@ -8,5 +8,9 @@ <y>eye</y> <y>billow</y> <y>a longer string</y> + <from>$</from> + <from>\</from> + <to>\$</to> + <to>$\backslash$</to> </strings> </doc> diff --git a/tests/exslt/strings/replace.1.xsl b/tests/exslt/strings/replace.1.xsl index 0c9e86cd..f9a74423 100644 --- a/tests/exslt/strings/replace.1.xsl +++ b/tests/exslt/strings/replace.1.xsl @@ -7,8 +7,15 @@ <xsl:template match="/"> <xsl:variable name="x" select="doc/strings/x"/> <xsl:variable name="y" select="doc/strings/y"/> + <xsl:variable name="from" select="doc/strings/from"/> + <xsl:variable name="to" select="doc/strings/to"/> + <xsl:variable name="result" select="str:replace('a', 'b', 'c')"/> <out>; + result nodes: <xsl:value-of select="count($result)"/> + result text nodes: <xsl:value-of select="count($result/self::text())"/> + result string: <xsl:value-of select="$result/self::text()"/> + str:replace('a, simple, list', ', ', '-') <xsl:copy-of select="str:replace('a, simple, list', ', ', '-')"/> @@ -30,6 +37,12 @@ str:replace('fee, fi, fo, fum', $x, 'j') <xsl:copy-of select="str:replace('fee, fi, fo, fum', $x, 'j')" /> + str:replace('foo', '', 'baz') + <xsl:copy-of select="str:replace('foo', '', 'baz')" /> + + str:replace('Price is $1.10', $from, $to) + <xsl:copy-of select="str:replace('Price is $1.10', $from, $to)" /> + </out> </xsl:template> |