Bug 2397 - Using substring() function with a string which has an apostrophe causes an exception
Summary: Using substring() function with a string which has an apostrophe causes an ex...
Status: NEW
Alias: None
Product: XalanJ1
Classification: Unclassified
Component: Xalan (show other bugs)
Version: 1.x
Hardware: PC All
: P3 critical (vote)
Target Milestone: ---
Assignee: Scott Boag
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-06-29 08:27 UTC by heather
Modified: 2005-03-20 17:06 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description heather 2001-06-29 08:27:54 UTC
Using substring() function with a string which has an apostrophe causes the 
following error message:
org.apache.xalan.xslt.XSLProcessorException: String index out of range: 29

Details:
I have a template which takes a string parameter and inserts <br/>s
in the string if there are no spaces in the string and the string is greater
than 32 characters.  It just prints out the string as is if there are
spaces.  This works just fine unless I try to pass it a string with a
special character.  For example, my string = "It doesn't work like this."  This 
string gets passed to the XSLT as an <xsl:param .../>.  If I pass the template 
a string with an apostraphe then I get the following error:
org.apache.xalan.xslt.XSLProcessorException: String index out of range: 29

Here is the template:

<xsl:template name="splitString">
	<xsl:param name="string"/>
	<xsl:choose>
		<xsl:when test="string-length($string) > 32 and
not(contains(substring($string,1,32), ' '))">
			<xsl:value-of select =
"substring($string,1,32)"/><BR/>
			<xsl:call-template name="splitString">
				<xsl:with-param name="string"
select="substring($string,33,string-length($string))" />
			</xsl:call-template>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="$string"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

Any insight into how to get around this problem would be greatly appreciated. 

Thanks,
Heather