Skip to content

Commit 5ff4263

Browse files
committed
Fixes escaping of string values if the value contains signs which must be escaped.
1 parent 4b551b8 commit 5ff4263

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/main/resources/xsl/css3-model-serializer.xsl

+10-5
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
<xsl:when test="$valueProvider/(self::attribute(value)|self::cssm:value)">
3131
<xsl:sequence select="string($valueProvider)"/>
3232
</xsl:when>
33-
<xsl:when test="not($requires-quotes) and $valueProvider/(self::attribute(string)|self::cssm:string)">
34-
<xsl:sequence select="string($valueProvider)"/>
35-
</xsl:when>
3633
<xsl:otherwise>
3734
<xsl:apply-templates select="$valueProvider" mode="cssm:serialize">
3835
<xsl:with-param name="requires-quotes" select="$requires-quotes" tunnel="yes"/>
@@ -52,8 +49,16 @@
5249
<xsl:template match="@string | string" mode="cssm:serialize" priority="10">
5350
<xsl:param name="requires-quotes" select="true()" tunnel="yes" as="xs:boolean"/>
5451
<xsl:choose>
55-
<xsl:when test="$requires-quotes">
56-
<xsl:sequence select="'''' || . || ''''"/>
52+
<xsl:when test="$requires-quotes or matches(., '\s|&quot;|''|\\')">
53+
<xsl:variable name="q" select="
54+
if (matches(., '''')) then '&quot;' else ''''
55+
"/>
56+
<xsl:variable name="value" select="
57+
replace(., '(\\|' || $q || ')', '\\$1')
58+
">
59+
</xsl:variable>
60+
61+
<xsl:sequence select="$q || $value || $q"/>
5762
</xsl:when>
5863
<xsl:otherwise>
5964
<xsl:value-of select="."/>

0 commit comments

Comments
 (0)