Author: markt
Date: Sat Feb 12 19:35:26 2011
New Revision: 1070139
URL: http://svn.apache.org/viewvc?rev=1070139&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50726
Ensure that the use of the genStringAsCharArray does not result in String
constants that are too long for valid Java code.
Modified:
tomcat/trunk/java/org/apache/jasper/compiler/Generator.java
tomcat/trunk/webapps/docs/changelog.xml
Modified: tomcat/trunk/java/org/apache/jasper/compiler/Generator.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/Generator.java?rev=1070139&r1=1070138&r2=1070139&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/Generator.java (original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/Generator.java Sat Feb 12
19:35:26 2011
@@ -1975,20 +1975,36 @@ class Generator {
} else {
caOut = charArrayBuffer.getOut();
}
- String charArrayName = textMap.get(text);
- if (charArrayName == null) {
- charArrayName = "_jspx_char_array_" + charArrayCount++;
- textMap.put(text, charArrayName);
- caOut.printin("static char[] ");
- caOut.print(charArrayName);
- caOut.print(" = ");
- caOut.print(quote(text));
- caOut.println(".toCharArray();");
+ // UTF-8 is up to 4 bytes per character
+ // String constants are limited to 64k bytes
+ // Limit string constants here to 16k characters
+ int textIndex = 0;
+ int textLength = text.length();
+ while (textIndex < textLength) {
+ int len = 0;
+ if (textLength - textIndex > 16384) {
+ len = 16384;
+ } else {
+ len = textLength - textIndex;
+ }
+ String output = text.substring(textIndex, textIndex + len);
+ String charArrayName = textMap.get(output);
+ if (charArrayName == null) {
+ charArrayName = "_jspx_char_array_" + charArrayCount++;
+ textMap.put(output, charArrayName);
+ caOut.printin("static char[] ");
+ caOut.print(charArrayName);
+ caOut.print(" = ");
+ caOut.print(quote(output));
+ caOut.println(".toCharArray();");
+ }
+
+ n.setBeginJavaLine(out.getJavaLine());
+ out.printil("out.write(" + charArrayName + ");");
+ n.setEndJavaLine(out.getJavaLine());
+
+ textIndex = textIndex + len;
}
-
- n.setBeginJavaLine(out.getJavaLine());
- out.printil("out.write(" + charArrayName + ");");
- n.setEndJavaLine(out.getJavaLine());
return;
}
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1070139&r1=1070138&r2=1070139&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Sat Feb 12 19:35:26 2011
@@ -93,6 +93,11 @@
for web.xml does not trigger an error when Jasper parses the web.xml
file. (markt)
</fix>
+ <fix>
+ <bug>50726</bug>: Ensure that the use of the genStringAsCharArray does
+ not result in String constants that are too long for valid Java code.
+ (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Tribes">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]