Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=50726
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 12 Feb 2011 19:35:26 +0000 (19:35 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 12 Feb 2011 19:35:26 +0000 (19:35 +0000)
Ensure that the use of the genStringAsCharArray does not result in String constants that are too long for valid Java code.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1070139 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/jasper/compiler/Generator.java
webapps/docs/changelog.xml

index 4e088b2..4cec63c 100644 (file)
@@ -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;
             }
 
index 9816fa0..a9004ad 100644 (file)
         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">