tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Fesler <cf-li...@fesler.org>
Subject [patch] JspC.java (tomcat_4_branch) toPackageName() bug
Date Wed, 09 Apr 2003 18:16:22 GMT
In the latest tomcat_4_branch version of JspC.java (1.12.2.6),
toPackageName(String jspUri) fails to return a valid package
declaration if one of the path elements (i.e., directory names) begins
with a character that is a valid identifier part, but not a valid
identifier start. An example:

toPackageName("hope0/1.0.0/welcome")

*  JspC.java 1.12.2.6 returns:

      package hope0.1_0002e0_0002e0.welcome

      This fails to compile because a Java identifier may not begin with
      a numeral (Java Language Spec, section 3.8), as the second identifier
      (1_0002e0_0002e0) does.

*  JspC.java 1.12.2.6 with included patch returns:

      package hope0._1_0002e0_0002e0.welcome

      Which works just fine.

The patch also makes the indentation of the toPackageName() more
consistent; I used 4 spaces (not tabs) for each indent.

Chris Fesler
cf-lists@fesler.org

patch follows
-------------

Index: JspC.java
===================================================================
RCS file: /home/cvspublic/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/JspC.java,v
retrieving revision 1.12.2.6
diff -u -r1.12.2.6 JspC.java
--- JspC.java   17 Mar 2003 20:53:39 -0000      1.12.2.6
+++ JspC.java   9 Apr 2003 17:50:06 -0000
@@ -996,23 +996,29 @@
     private String toPackageName(String jspUri) {
         StringBuffer modifiedPackageName = new StringBuffer();
         int iSep = jspUri.lastIndexOf('/');
-       // Start after the first slash
+        // Start after the first slash
         int nameStart = 1;
-       for (int i = 1; i < iSep; i++) {
-           char ch = jspUri.charAt(i);
-           if (Character.isJavaIdentifierPart(ch)) {
-               modifiedPackageName.append(ch);
-           }
-           else if (ch == '/') {
+        for (int i = 1; i < iSep; i++) {
+            char ch = jspUri.charAt(i);
+
+            if (i == nameStart) {
+                if (! Character.isJavaIdentifierStart(ch)) {
+                    modifiedPackageName.append('_');
+                }
+            }
+
+            if (Character.isJavaIdentifierPart(ch)) {
+                modifiedPackageName.append(ch);
+            } else if (ch == '/') {
                 if (isJavaKeyword(jspUri.substring(nameStart, i))) {
                     modifiedPackageName.append('_');
                 }
                 nameStart = i+1;
-               modifiedPackageName.append('.');
-           } else {
-               modifiedPackageName.append(mangleChar(ch));
-           }
-       }
+                modifiedPackageName.append('.');
+            } else {
+                modifiedPackageName.append(mangleChar(ch));
+            }
+        }
         if (nameStart < iSep && isJavaKeyword(jspUri.substring(nameStart, iSep)))
{
             modifiedPackageName.append('_');
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message