Bug 15321

Summary: wordWrap throws StringArrayIndexOutOfBoundsExceptions
Product: Taglibs Reporter: Robert Taylor <rtaylor>
Component: String TaglibAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED WORKSFORME    
Severity: normal    
Priority: P3    
Version: 1.0   
Target Milestone: ---   
Hardware: Other   
OS: other   

Description Robert Taylor 2002-12-12 16:54:11 UTC
wordWrap seems to be blowing up if the tag attempts to wrap a string that
contains a newline character as the 81st character. It will not blow up
if the 81st character is not a new line character.

This is my usage:
<string:wordWrap><bean:write name="form" property="body" 
ignore="true"/></string:wordWrap>

Partial stack trace:
2120: java.lang.StringIndexOutOfBoundsException: String index out of range: 80
2120:   at java.lang.String.charAt(String.java:455)
2120:   at org.apache.taglibs.string.util.StringW.wordWrap(StringW.java:181)
2120:   at org.apache.taglibs.string.WordWrapTag.changeString
(WordWrapTag.java:159)
2120:   at org.apache.taglibs.string.StringTagSupport.doEndTag
(StringTagSupport.java:135)
Comment 1 Henri Yandell 2003-01-28 23:14:44 UTC
Ought to be fixed. Awaiting confirmation.
Comment 2 Felipe Leme 2004-03-10 04:20:37 UTC
Robert,

Could you please try it again and, if the bug persists, reopen the bug providing
a better test case?

For instance, I created the following JSP page:

<%-- jsp page starts here --%>
<%@ taglib uri="http://jakarta.apache.org/taglibs/string-1.0.1" prefix="str" %>

<%

StringBuffer buffer = new StringBuffer(100);

for ( int i=1; i<=80; i++ ) {
   buffer.append( (char) i%10 );
}

String word = request.getParameter("word");
if ( word == null ) {
   word = "";
}
%>

Word: <str:wordWrap><%=word%></str:wordWrap>
<br>
Length: <str:length><%=word%></str:length>

<form>

Word: <textarea cols="80" rows="10" name="word"><%=buffer.toString()%></textArea>
<br>
<input type="submit">
</form>
<%-- jsp page ends here --%>

And ran it with many inputs:

http://localhost:8080/taglibs/bug15321.jsp?word=12345678901234567890123456789012345678901234567890123456789012345678901234567890
http://localhost:8080/taglibs/bug15321.jsp?word=12345678901234567890123456789012345678901234567890123456789012345678901234567890%0D
http://localhost:8080/taglibs/bug15321.jsp?word=12345678901234567890123456789012345678901234567890123456789012345678901234567890%0A
http://localhost:8080/taglibs/bug15321.jsp?word=12345678901234567890123456789012345678901234567890123456789012345678901234567890%0A%0D


None of them caused an exception, so I think it might have been already fixed.

Felipe